-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
50 lines (46 loc) · 1.1 KB
/
sw.js
File metadata and controls
50 lines (46 loc) · 1.1 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
// https://developer.mozilla.org/zh-CN/docs/Web/Progressive_web_apps
// service world.
const versicer= 1;
const nomo= 'TEKSTO' + versicer;
const resFl= [
// '/',
// '/index.html',
'res/font/N4694-ciuj.woff2',
'res/font/NotoSerifTangut-Regular.woff2',
'res/site/background.jpg',
'res/site/bgmap.jpg',
'res/icon/Cabbage_128.png',
'res/icon/Cabbage_160.png',
'res/icon/Cabbage_256.png',
'res/icon/Cabbage_512.png',
'res/cabbage.png',
'manifest.json'
]
// Install.
self.addEventListener('install', e=>{
e.waitUntil(
caches.open(nomo).then(cz=> cz.addAll(resFl))
)
})
// Fetch.
self.addEventListener('fetch', e=>{
e.respondWith(
caches.match(e.request).then(fz=>{
console.log('Fetch list: ', fz)
return fz || fetch(e.request).then(cz=>{
cz.put(e.request, response.clone());
return response;
})
})
)
})
// Activate.
self.addEventListener('activate', e=>{
e.waitUntil()
caches.keys().then(lz=> {
return Promise.all(lz.map(ky=>{
if(nomo.indexOf(ky) === -1){return caches.delete(ky)}
}))
})
})
// self.addEventListener('', e=>{})