-
Notifications
You must be signed in to change notification settings - Fork 2
/
sw-manual.js
86 lines (79 loc) · 2.12 KB
/
sw-manual.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
const cacheName = "simtiva-manual-v1-1";
const assets = [
"/",
"/manual.html",
"/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",
"/icon.png",
"/icon1024.webp",
"/fonts/BrandonText-Bold.otf",
"/fonts/SourceSans3-Regular.otf.woff2",
"/fonts/SourceSans3-Bold.otf.woff2",
"/fonts/SourceSans3-It.otf.woff2",
"/fonts/SourceSans3-BoldIt.otf.woff2",
"/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);
})
);
});