-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
31 lines (30 loc) · 921 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
self.addEventListener("install", function (event) {
console.log("[Service Worker] Installing Service Worker ...", event);
event.waitUntil(
caches.open("static").then(function (cache) {
console.log("precaching");
cache.add("/index.html");
cache.add("/");
})
);
});
self.addEventListener("activate", function (event) {
console.log("[Service Worker] Activating Service Worker ...", event);
return self.clients.claim();
});
self.addEventListener("fetch", function (event) {
console.log("[Service Worker] Fetching something ....", event);
event.respondWith(
caches.match(event.request).then(function (response) {
if (response) {
return response;
} else {
return fetch(event.request);
}
})
);
});
self.addEventListener("push", (event) => {
const notification = event.data.text();
self.registration.showNotification(notification, {});
});