-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
67 lines (62 loc) · 1.86 KB
/
sw.js
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
const VERSION_NAME = "2.4.0dev";
const VERSION_CODE = 20399;
const CACHE_NAME = `koilors-${VERSION_NAME}`;
const APP_STATIC_RESOURCES = [
"/Koilors/",
"/Koilors/index.html",
"/Koilors/scripts/canvas-worker.js",
"/Koilors/scripts/color.global.js",
"/Koilors/scripts/colorpicker.js",
"/Koilors/scripts/data-model.js",
"/Koilors/scripts/data-view.js",
"/Koilors/scripts/extras.js",
"/Koilors/scripts/filesystem.js",
"/Koilors/scripts/livedata.js",
"/Koilors/scripts/okcolor.js",
"/Koilors/scripts/rendering.js",
"/Koilors/scripts/schemes.js",
"/Koilors/scripts/text-slider.js",
"/Koilors/scripts/utils.js",
"/Koilors/styles/kofi.css",
"/Koilors/styles/roles-dark.css",
"/Koilors/styles/roles-light.css",
"/Koilors/styles/roles.css",
"/Koilors/styles/style.css"
];
self.addEventListener("install", (event) => {
event.waitUntil(
(async () => {
const cache = await caches.open(CACHE_NAME);
cache.addAll(APP_STATIC_RESOURCES);
})(),
);
});
self.addEventListener("activate", (event) => {
event.waitUntil(
(async () => {
const names = await caches.keys();
await Promise.all(
names.map((name) => {
if (name !== CACHE_NAME) {
return caches.delete(name);
}
}),
);
await clients.claim();
})(),
);
});
self.addEventListener("fetch", (e) => {
e.respondWith(
(async () => {
const r = await caches.match(e.request);
if (r) {
return r;
}
const response = await fetch(e.request);
const cache = await caches.open(CACHE_NAME);
cache.put(e.request, response.clone());
return response;
})(),
);
});