-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathservice-worker.js
More file actions
41 lines (41 loc) · 1.27 KB
/
Copy pathservice-worker.js
File metadata and controls
41 lines (41 loc) · 1.27 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
const cacheName = 'confusify-cache';
const filestoCache = [
'./',
'./index.html',
'./createList.html',
'./assets/logo_light.svg',
'./assets/logo_light.png',
'./assets/logo.svg',
'./data/list.json',
'./data/list.txt',
'./data/safelist.json',
'./js/consoleConvert.js',
'./js/createList.js',
'./js/index.js',
'./manifest.json',
'./style.css',
'https://fonts.googleapis.com/css2?family=Work+Sans:ital,wght@0,100..900;1,100..900&display=swap'
];
self.addEventListener('install', e => {
e.waitUntil(
caches.open(cacheName)
.then(cache => cache.addAll(filestoCache))
);
});
self.addEventListener('activate', e => self.clients.claim());
self.addEventListener('fetch', event => {
const req = event.request;
if (req.url.indexOf("updatecode") !== -1) event.respondWith(fetch(req)); else event.respondWith(networkFirst(req));
});
async function networkFirst(req) {
try {
const networkResponse = await fetch(req);
const cache = await caches.open(cacheName);
await cache.delete(req);
await cache.put(req, networkResponse.clone());
return networkResponse;
} catch (error) {
const cachedResponse = await caches.match(req);
return cachedResponse;
}
}