Repository navigation
Expand file tree
/
Copy pathsw.js
More file actions
58 lines (55 loc) · 1.44 KB
/
Copy pathsw.js
File metadata and controls
58 lines (55 loc) · 1.44 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
57
58
const CACHE = 'devtools-v1';
const ASSETS = [
'/',
'/style.css',
'/script.js',
'/tools/json-formatter',
'/tools/base64',
'/tools/url-encode',
'/tools/unicode',
'/tools/html-entity',
'/tools/markdown-preview',
'/tools/regex-tester',
'/tools/text-diff',
'/tools/word-count',
'/tools/lorem-ipsum',
'/tools/csv-json',
'/tools/jwt-decoder',
'/tools/url-parser',
'/tools/cron-parser',
'/tools/qrcode-gen',
'/tools/uuid-gen',
'/tools/password-gen',
'/tools/palette-gen',
'/tools/image-compress',
'/tools/image-to-base64',
'/tools/color-picker',
'/tools/timestamp',
'/tools/number-base',
'/tools/unit-converter',
'/tools/pdf-merge',
'/tools/file-hash',
'/privacy',
'/terms',
'/about'
];
self.addEventListener('install', e => {
e.waitUntil(caches.open(CACHE).then(c => c.addAll(ASSETS).catch(() => {})));
self.skipWaiting();
});
self.addEventListener('activate', e => {
e.waitUntil(caches.keys().then(keys => Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))));
self.clients.claim();
});
self.addEventListener('fetch', e => {
if (e.request.method !== 'GET') return;
e.respondWith(
caches.match(e.request).then(cached => {
const fetched = fetch(e.request).then(res => {
if (res.ok) { const clone = res.clone(); caches.open(CACHE).then(c => c.put(e.request, clone)); }
return res;
}).catch(() => cached);
return cached || fetched;
})
);
});