-
Notifications
You must be signed in to change notification settings - Fork 1
/
sw.js
60 lines (55 loc) · 1.22 KB
/
sw.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const CACHE_NAME = "v7";
const CACHE_URLS = [
"/",
"/index.css",
"/index.js",
"/favicon.ico",
"/manifest.webmanifest",
"/images/logo-16.png",
"/images/logo-32.png",
"/images/logo-48.png",
"/images/logo-96.png",
"/images/logo-144.png",
"/images/logo-192.png",
"/images/logo-192-opaque.png",
"/images/logo-384.png",
"/images/logo-maskable-48.png",
"/images/logo-maskable-96.png",
"/images/logo-maskable-144.png",
"/images/logo-maskable-192.png",
"/images/logo-maskable-384.png",
];
addEventListener("install", (event) => {
self.skipWaiting();
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => cache.addAll(CACHE_URLS))
);
});
addEventListener("activate", (event) => {
event.waitUntil(
caches.keys().then((cacheNames) =>
Promise.all(
cacheNames.map((cacheName) => {
if (cacheName !== CACHE_NAME) {
return caches.delete(cacheName);
}
})
)
)
);
});
addEventListener("fetch", (event) => {
event.respondWith(
caches.match(event.request).then((response) => {
if (response) {
return response;
}
return fetch(event.request);
})
);
});
addEventListener("message", (event) => {
if (event.data === "version") {
event.source.postMessage({ version: CACHE_NAME });
}
});