-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsw.js
47 lines (44 loc) · 1.12 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
const cacheName = 'cache-v1416-20250116-1';
const precacheResources = [
'./',
'index.html',
'lib.css',
'main.css',
'main.js',
'apple-touch-icon.png',
'favicon-32x32.png',
'favicon-16x16.png',
'site.webmanifest',
'safari-pinned-tab.svg',
'android-chrome-192x192.png',
'android-chrome-512x512.png'
];
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(cacheName).then((cache) => cache.addAll(precacheResources)));
self.skipWaiting();
});
self.addEventListener('activate', (event) => {
const cachesToKeep = [cacheName];
event.waitUntil(
caches.keys().then((keyList) =>
Promise.all(
keyList.map((key) => {
if (!cachesToKeep.includes(key)) {
return caches.delete(key);
}
})
)
)
);
});
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request).then((cachedResponse) => {
if (cachedResponse) {
return cachedResponse;
}
return fetch(event.request);
})
);
});