-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
44 lines (35 loc) · 936 Bytes
/
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
const cacheName = 'n&d-v1';
const staticAssets = [
'index.html',
'manifest.webmanifest',
'assets/style.css',
'assets/jquery-3.5.1.min.js',
'assets/script.js',
'assets/icon-96.png',
'assets/icon-512.png',
'assets/bird.gif',
'assets/mount.png',
'assets/star.gif',
];
self.addEventListener('install', async e => {
const cache = await caches.open(cacheName);
await cache.addAll(staticAssets);
return self.skipWaiting();
});
self.addEventListener('activate', evt => {
evt.waitUntil(
caches.keys().then(keys => {
return Promise.all(keys
.filter(key => key !== cacheName)
.map(key => caches.delete(key))
);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request).then(cacheRes => {
return cacheRes || fetch(event.request)
})
)
});