forked from lazy-guy/tomodoro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
40 lines (38 loc) · 917 Bytes
/
sw.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
const cacheName = "clock";
const contentToCache = [
"./",
"./index.html",
"./index.css",
"./index.js",
"./worker.js",
"./sw.js",
"./icons/icon192.png",
"./icons/icon512.png",
"./icons/maskable192.png",
"./icons/maskable512.png",
"./site.webmanifest",
"./icons/favicon.png",
"./icons/appletouch.png",
"./GitHub-Mark-64px.png"
];
self.addEventListener("install", (e) => {
console.log("Service Worker installed");
e.waitUntil(
(async () => {
const cache = await caches.open(cacheName);
await cache.addAll(contentToCache).catch(err => console.log(err));
})()
);
});
self.addEventListener("fetch", function (event) {
event.respondWith(fetch(event.request).then((res) => {
let response = res.clone();
caches.open(cacheName).then((cache) => {
cache.put(event.request, response);
});
return res
}).catch((err) => {
return caches.match(event.request)
})
);
});