-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsw.js
More file actions
65 lines (63 loc) · 1.64 KB
/
Copy pathsw.js
File metadata and controls
65 lines (63 loc) · 1.64 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
/**
* バージョンを示す整数値.
* sw.js以外の任意のhtml,jsファイルに変更がある場合この値を加算すること
* ファイルの追加がある場合は下の files も更新する
*/
const VERSION = 1;
const files = [
"/aboutus",
"/disclaimer",
"/errorMessage/error1.txt",
"/errorMessage/error2.txt",
"/errorMessage/error3.txt",
"/errorMessage/error4.txt",
"/errorMessage/error5.txt",
"/errorMessage/error6.txt",
"/howToUse",
"/",
"/lz-string.min.js",
"/notion",
"/resources/favicon-utcode.png",
"/resources/utc-logo.svg",
"/script.js",
"/style.css",
"/material-icons.css",
"https://cdn.jsdelivr.net/npm/@material-design-icons/font@0.14.15/material-icons.woff2",
];
self.addEventListener("install", (e) => {
e.waitUntil(
(async () => {
const c = await self.caches.open("main" + VERSION);
await c.addAll(files);
})(),
);
});
self.addEventListener("activate", (e) => {
// 古いキャッシュを削除する
e.waitUntil(
(async () => {
const keys = await self.caches.keys();
await Promise.all(
keys
.filter((key) => key !== "main" + VERSION)
.map((key) => self.caches.delete(key)),
);
})(),
);
});
self.addEventListener("fetch", (e) => {
if (e.request.url.startsWith("https://www.googletagmanager.com")) {
return;
}
e.respondWith(
(async () => {
const c = await self.caches.open("main" + VERSION);
const res = await c.match(e.request);
if (res) {
return res;
}
console.warn(`${e.request.url} is not in cache in sw.js`);
return fetch(e.request);
})(),
);
});