-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
33 lines (29 loc) · 680 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
const VERSION = 'v11';
const onCache = cache => cache.addAll([
'./',
'./index.html',
'./index.css',
'./skeleton.css',
'./index.js',
'./fetch.js',
'./util.js',
'./data.js',
'./img/kirpan.jpg',
'./img/sword.png',
]);
this.addEventListener('install', e => e.waitUntil(
caches
.open(VERSION)
.then(onCache)
));
this.addEventListener('activate', e => e.waitUntil(caches
.keys()
.then(cs => cs.filter(c => c !== VERSION))
.then(cs => Promise.all(cs.map(c => caches.delete(c))))
.then(() => self.clients.claim())
));
this.addEventListener('fetch', e => e.respondWith(
caches
.match(e.request)
.then(res => res || fetch(e.request))
));