-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
37 lines (33 loc) · 1.06 KB
/
service-worker.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
const cacheName = "v1";
const cacheAssets = ["index.html", "dist/src/app.js", "dist/src/notification.js", "dist/src/ntc.js", "dist/src/shortcuts.js", "dist/styles/style.css"];
self.addEventListener("install", (e) => {
// console.log("Service Worker: Installed");
e.waitUntil(
caches
.open(cacheName)
.then((cache) => {
// console.log("Service Worker: Cashing Files");
cache.addAll(cacheAssets);
})
.then(() => self.skipWaiting())
);
});
self.addEventListener("activate", (e) => {
// console.log("Service Worker: Activated");
e.waitUntil(
caches.keys().then((cacheName) => {
return Promise.all(
cacheName.map((cache) => {
if (cache !== cacheName) {
// console.log("Service Worker: Clearing Old Cache");
return caches.delete(cache);
}
})
);
})
);
});
self.addEventListener("fetch", (e) => {
// console.log("Service Worker: Fetching");
e.respondWith(fetch(e.request).catch(() => caches.match(e.request)));
});