-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
43 lines (34 loc) · 891 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
const cacheName = 'rps-v1';
const staticAssets = [
'index.html',
'manifest.webmanifest',
'assets/style.css',
'assets/script.js',
'assets/p.png',
'assets/r.png',
'assets/s.png',
'assets/icon-96.png',
'assets/icon-512.png'
];
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)
})
)
});