-
Notifications
You must be signed in to change notification settings - Fork 2
/
serviceworker.js
98 lines (91 loc) · 2.4 KB
/
serviceworker.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
const cacheName = "simtiva-v4-111-plusmanualv2";
const assets = [
"/",
"/index.html",
"/manual.html",
"/main.js",
"/chartjs-plugin-crosshair.min.js",
"/styles.css",
"/css/fontawesome.min.css",
"/css/regular.min.css",
"/css/brands.min.css",
"/css/solid.min.css",
"/webfonts/fa-solid-900.ttf",
"/webfonts/fa-solid-900.woff2",
"/webfonts/fa-regular-400.ttf",
"/webfonts/fa-regular-400.woff2",
"/webfonts/fa-brands-400.ttf",
"/webfonts/fa-brands-400.woff2",
"/chart.min.js",
"/beep.mp3",
"/beep-2.mp3",
"/eleveld1.gif",
"/eleveld2.gif",
"/icon.png",
"/icon1024.webp",
"/apple-touch-icon-180x180.png",
"/fonts/BrandonText-Bold.otf",
"/fonts/SourceSans3-Regular.otf.woff2",
"/fonts/SourceSans3-Bold.otf.woff2",
"/fonts/SourceSans3-It.otf.woff2",
"/fonts/SourceSans3-BoldIt.otf.woff2",
"/lz-string.js",
"/es.json",
"/fr.json",
"/zh.json",
"/ja.json",
"/pt.json",
"/ru.json"
]
self.addEventListener('activate', event => {
console.log('now ready to handle fetches!');
event.waitUntil(
caches.keys().then(function(cacheNames) {
console.log(cacheNames);
var promiseArr = cacheNames.map(function(item) {
if (item !== cacheName) {
// Delete that cached file
console.log("deleted " + item);
return caches.delete(item);
}
})
return Promise.all(promiseArr);
})
); // end e.waitUntil
});
//old activate code
/*
self.addEventListener('activate', function(event) {
console.log("activation. ready to handle fetches.");
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.filter(function(cacheName) {
// Return true if you want to remove this cache,
// but remember that caches are shared across
// the whole origin
}).map(function(cacheName) {
return caches.delete(cacheName);
})
);
})
);
});
*/
//end old activate code
self.addEventListener("install", installEvent => {
self.skipWaiting();
console.log("installing...");
installEvent.waitUntil(
caches.open(cacheName).then(cache => {
cache.addAll(assets)
}))
})
//ref: https://web.dev/offline-cookbook/#network-falling-back-to-cache
self.addEventListener('fetch', function(event) {
event.respondWith(
fetch(event.request).catch(function() {
return caches.match(event.request);
})
);
});