-
Notifications
You must be signed in to change notification settings - Fork 0
/
serviceWorker.js
41 lines (38 loc) · 1 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
const cacheID = "syncboard4js-pwa-234"
const assets = [
".",
"index.html",
"css/halfmoon-variables.min.css",
"js/halfmoon.min.js",
"js/socket.io.min.js",
"js/socket.io.min.js.map",
"js/app.js",
"js/socket.js",
"js/sync.js",
"images/icons/internet.svg",
"images/icons/icon-512x512.png"
]
self.addEventListener("install", installEvent => {
installEvent.waitUntil(
caches.open(cacheID).then(cache => {
cache.addAll(assets).then();
})
)
});
self.addEventListener("fetch", fetchEvent => {
fetchEvent.respondWith(async function() {
try {
return await fetch(fetchEvent.request);
} catch (err) {
return caches.match(fetchEvent.request);
}
}());
});
self.addEventListener("message", messageEvent => {
if (messageEvent.data === "clear-cache") {
caches.keys().then(function (names) {
for (let name of names)
caches.delete(name).then();
});
}
});