-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
43 lines (39 loc) · 1.15 KB
/
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
41
42
43
var cacheName = 'ClashZ-v0.0.1'
var cacheFiles = [
'./index.html',
'./js/app.js',
'./css/bulma.min.css',
'./css/main.css',
'./images/icons/logo-32.png',
'./images/icons/logo-128.png',
'./images/icons/logo-144.png',
'./images/icons/logo-152.png',
'./images/icons/logo-192.png',
'./images/icons/logo-256.png',
'./images/icons/logo-512.png'
]
self.addEventListener('install', e => {
console.log('[ClashZ - ServiceWorker] Install');
e.waitUntil(
caches.open(cacheName).then(cache => {
console.log('[ClashZ - ServiceWorker] Caching')
return cache.addAll(cacheFiles)
})
)
})
self.addEventListener('activate', e => {
console.log('[ClashZ - ServiceWorker] Activate');
e.waitUntil(
caches.keys().then(keyList => {
return Promise.all(keyList.map(key => {
if (key !== cacheName) {
console.log('[ClashZ - ServiceWorker] Removing old cache', key)
return caches.delete(key)
}
}))
})
)
return self.clients.claim()
})
self.addEventListener('fetch', e => {
});