-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathsw.js
More file actions
38 lines (37 loc) · 1.2 KB
/
sw.js
File metadata and controls
38 lines (37 loc) · 1.2 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
(function () {
self.importScripts("https://cdn.jsdelivr.net/npm/sw-toolbox@3.6.0/sw-toolbox.min.js");
// self.importScripts("/v2ray/sw-toolbox.js");
self.toolbox.router.get('/(.*)', self.toolbox.networkFirst, {
cache: {
name: 'sw'
}
});
self.toolbox.router.get('/(.*)', self.toolbox.cacheFirst, {
origin: /cdnjs\.cloudflare\.com/,
cache: {
name: 'static'
}
});
self.toolbox.router.get('/(.*)', self.toolbox.cacheFirst, {
origin: /cdn\.jsdelivr\.net/,
cache: {
name: 'jsdelivr'
}
});
self.addEventListener('install', function (event) {
return event.waitUntil(self.skipWaiting())
});
self.addEventListener('activate', function (event) {
// return event.waitUntil(self.clients.claim())
var cacheWhitelist = ['sw','static'];
event.waitUntil(
caches.keys().then(function (keyList) {
return Promise.all(keyList.map(function (key) {
if (cacheWhitelist.indexOf(key) === -1) {
return caches.delete(key);
}
}));
})
);
})
})();