-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
48 lines (43 loc) · 1.05 KB
/
service-worker.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
const cacheVerison = "0.0.4"
self.addEventListener("install", event => {
event.waitUntil(
caches
.open(cacheVerison)
.then(cache =>
cache.addAll([
"./",
"./index.html",
"./index.css",
"./src/store.mjs",
"./src/util.mjs",
"./src/elements/app.mjs",
"./src/elements/build-context-list.mjs",
"./src/elements/context-card.mjs",
"./src/elements/edit-context-card.mjs"
])
)
)
event.waitUntil(self.skipWaiting())
})
if (location.hostname !== "localhost")
self.addEventListener("fetch", event =>
event.respondWith(
caches
.match(event.request)
.then(response => response || fetch(event.request))
)
)
self.addEventListener("activate", event => {
event.waitUntil(
caches.keys()
.then(keyList =>
Promise.all(
keyList.map(key => {
if (key != cacheVerison)
return caches.delete(key)
})
)
)
)
event.waitUntil(self.clients.claim())
})