-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceWorker.js
40 lines (38 loc) · 1.13 KB
/
serviceWorker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const SCROBBLERADIO_CACHE = "app-v3.023"; // Updated cache version
const staticPlayer = SCROBBLERADIO_CACHE;
const assets = [
"/",
"/css/style.css",
"/js/main-dist.js",
"/js/stations-dist.js",
"/img/defaultArt.png",
"css/external/bootstrap.min.css",
"js/external/bootstrap.min.js",
"js/external/filter.min.js"
];
// Install event: Caches the assets
self.addEventListener("install", (installEvent) => {
installEvent.waitUntil(
caches.open(staticPlayer).then((cache) => {
console.log("Caching assets");
return cache.addAll(assets);
})
);
self.skipWaiting(); // Forces the new SW to activate immediately
});
// Activate event: Cleans up old caches
self.addEventListener("activate", (activateEvent) => {
activateEvent.waitUntil(
caches.keys().then((cacheNames) => {
return Promise.all(
cacheNames.map((cache) => {
if (cache !== staticPlayer) {
console.log("Deleting old cache:", cache);
return caches.delete(cache); // Delete old caches
}
})
);
})
);
self.clients.claim(); // Immediately start controlling any open pages
});