-
Notifications
You must be signed in to change notification settings - Fork 0
/
app-worker.js
43 lines (38 loc) · 1.07 KB
/
app-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
const cacheName = "app-" + "716d074d0645d063901420068c432d46ef9c9cc7";
self.addEventListener("install", event => {
console.log("installing app worker 716d074d0645d063901420068c432d46ef9c9cc7");
event.waitUntil(
caches.open(cacheName).
then(cache => {
return cache.addAll([
"index.html",
"https://storage.googleapis.com/murlok-github/icon-192.png",
"https://storage.googleapis.com/murlok-github/icon-512.png",
]);
}).
then(() => {
self.skipWaiting();
})
);
});
self.addEventListener("activate", event => {
event.waitUntil(
caches.keys().then(keyList => {
return Promise.all(
keyList.map(key => {
if (key !== cacheName) {
return caches.delete(key);
}
})
);
})
);
console.log("app worker 716d074d0645d063901420068c432d46ef9c9cc7 is activated");
});
self.addEventListener("fetch", event => {
event.respondWith(
caches.match(event.request).then(response => {
return response || fetch(event.request);
})
);
});