-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
executable file
·56 lines (51 loc) · 1.26 KB
/
sw.js
File metadata and controls
executable file
·56 lines (51 loc) · 1.26 KB
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
const versionNumber = 'v13';
self.addEventListener('install', event => {
event.waitUntil(
caches.open(versionNumber).then(cache => {
return cache.addAll([
'/',
'/index.html',
'/favicon.ico',
'/static/logo.png',
'/static/logo/128.png',
'/static/logo/144.png',
'/static/logo/192.png',
'/static/logo/192t.png',
'/static/logo/192t2.png',
'/static/main.js',
'/static/swiped.min.js',
'/static/main.css',
'/static/manifest.json',
'/static/Roboto.woff2',
]);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(caches.match(event.request).then(response => {
if (response !== undefined) {
return response;
} else {
return fetch(event.request).then(response => {
let responseClone = response.clone();
caches.open(versionNumber).then(cache => {
cache.put(event.request, responseClone);
});
return response;
}).catch(() => {
return caches.match('/static/logo.png');
});
}
}));
});
self.addEventListener('activate', event => {
const cacheKeeplist = [ versionNumber ];
event.waitUntil(
caches.keys().then(keyList => {
return Promise.all(keyList.map(key => {
if (cacheKeeplist.indexOf(key) === -1)
return caches.delete(key);
}));
})
);
});