-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
100 lines (74 loc) · 2.62 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const cache_name = 'fingerprint-v0.0.27';
const app_files = [
// HTML
"./index.html",
// CSS
"./css/bootstrap.min.css",
"./css/fingerprint.css",
"./css/toastify.min.css",
// Javascript dependencies
"./javascript/FileSaver.min.js",
"./javascript/XmlBeautify.js",
"./javascript/jquery-3.6.3.min.js",
"./javascript/localforage.min.js",
"./javascript/raphael.min.js",
"./javascript/toastify.js",
"./javascript/simplify.js",
"./javascript/fit-curve.min.js",
"./javascript/wasm_exec.js",
"./javascript/sfomuseum.wasm.js",
// Javascript application
"./javascript/fingerprint.raphael.sketchpad.js",
"./javascript/fingerprint.application.js",
"./javascript/fingerprint.capabilities.js",
"./javascript/fingerprint.colours.js",
"./javascript/fingerprint.exif.js",
"./javascript/fingerprint.controls.js",
"./javascript/fingerprint.drawing.js",
"./javascript/fingerprint.export.js",
"./javascript/fingerprint.feedback.js",
"./javascript/fingerprint.import.js",
"./javascript/fingerprint.init.js",
"./javascript/fingerprint.menu.js",
"./javascript/fingerprint.offline.js",
"./javascript/fingerprint.render.js",
"./javascript/fingerprint.share.js",
"./javascript/fingerprint.storage.js",
"./javascript/fingerprint.viewsource.js",
// WASM
"./wasm/update_exif.wasm",
// Javascript service workers
"./sw.js"
];
self.addEventListener("install", (e) => {
console.log("SW installed", cache_name);
e.waitUntil((async () => {
const cache = await caches.open(cache_name);
// console.log('[Service Worker] Caching all: app shell and content');
await cache.addAll(app_files);
})());
});
addEventListener("activate", (event) => {
console.log("SW activate", cache_name);
});
addEventListener("message", (event) => {
// event is a MessageEvent object
console.log(`The service worker sent me a message: ${event.data}`);
});
self.addEventListener('fetch', (e) => {
// https://developer.mozilla.org/en-US/docs/Web/API/Cache
e.respondWith((async () => {
console.log("fetch", cache_name, e.request.url);
const cache = await caches.open(cache_name);
const r = await cache.match(e.request);
console.log(`[Service Worker] Fetching resource: ${e.request.url}`);
if (r) {
console.log("return cache", e.request.url);
return r;
}
const response = await fetch(e.request);
console.log(`[Service Worker] Caching new resource: ${e.request.url}`);
cache.put(e.request, response.clone());
return response;
})());
});