-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
73 lines (58 loc) · 3.34 KB
/
Copy pathsw.js
File metadata and controls
73 lines (58 loc) · 3.34 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const static = ["/favicon.ico", "/fonts/uisli.ttf", "/fonts/subset-Symbol.woff2", "/fonts/oeui.ttf", "/fonts/subset.woff2", "/fonts/oeuiz.ttf", "/fonts/uili.woff2", "/fonts/uisb.ttf", "/fonts/oeui.woff2", "/fonts/oeuii.ttf", "/fonts/uisbi.ttf", "/fonts/oeuisl.ttf", "/fonts/uisli.woff2", "/fonts/uibli.ttf", "/fonts/uisym.woff2", "/fonts/uisb.woff2", "/fonts/oeuisl.woff2", "/fonts/oeuib.woff2", "/fonts/subset-Symbol.ttf", "/fonts/uiemj.woff2", "/fonts/uiemj.ttf", "/fonts/oeuiz.woff2", "/fonts/uihis.ttf", "/fonts/oeuii.woff2", "/fonts/uisbi.woff2", "/fonts/subset.ttf", "/fonts/oeuil.ttf", "/fonts/uibl.ttf", "/fonts/uisym.ttf", "/fonts/uibl.woff2", "/fonts/uibli.woff2", "/fonts/uili.ttf", "/fonts/subset-Bold.woff2", "/fonts/subset-Bold.ttf", "/fonts/oeuil.woff2", "/fonts/oeuib.ttf", "/fonts/uihis.woff2", "/icon.png", "/images/Inlook.webp", "/images/Bopper.webp", "/images/Foresight.webp", "/images/FurriousFox.webp", "/email.svg", "/icons/back.gif", "/icons/binary.gif", "/icons/blank.gif"];
const prefetch = ["/favicon.ico", "/icon.png", "/images/Inlook.webp", "/images/Bopper.webp", "/images/Foresight.webp", "/images/FurriousFox.webp", "/", "/icons/back.gif", "/icons/binary.gif", "/icons/blank.gif"];
self.addEventListener("install", (_event) => {
self.skipWaiting();
});
self.addEventListener("activate", (event) => {
event.waitUntil((async () => {
const cache = await caches.open("argv");
await cache.addAll(prefetch);
await clients.claim();
})());
});
self.addEventListener("fetch", (event) => {
let a = false;
let b = false;
event.respondWith((async () => {
const pathname = new URL(event.request.url).pathname;
if (static.includes(pathname)) {
const r = await caches.match(event.request);
if (r) return r;
const response = await fetch(event.request);
if (response.status === 200) {
const cache = await caches.open("argv");
cache.put(event.request, response.clone());
}
return response;
}
if (pathname == "/" || pathname == "/index.html") {
const postfetch = (async () => {
const response = await fetch(event.request);
if (response.status === 200) {
if (!a && !b) {
const old_res = await (await caches.match(event.request)).text();
const new_res = await response.clone().text();
if (new_res == old_res || new_res.length < 1) return;
const client = await self.clients.get(event.resultingClientId || event.clientId);
if (client) {
client.postMessage(await response.clone().blob());
}
}
const cache = await caches.open("argv");
cache.put(event.request, response.clone());
}
return response;
})();
event.waitUntil(postfetch);
const r = await caches.match(event.request);
if (r) {
setTimeout(() => b = true, 500);
return r;
}
a = true;
return await postfetch;
}
const response = await fetch(event.request);
return response;
})());
});