-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceWorker.js
40 lines (36 loc) · 960 Bytes
/
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
const staticWebApp = "mist-showcase-site";
// store the assets
const assets = [
"/",
"/index.html",
"/main.css",
"/js/app.js",
"/images/wp4155374-mist-wallpapers.jpg",
"/images/wp4155375-mist-wallpapers.jpg",
"/images/wp4155376-mist-wallpapers.jpg",
];
// cache the assets
self.addEventListener("install", (installEvent) => {
installEvent.waitUntil(
caches.open(staticWebApp).then((cache) => {
cache.addAll(assets);
})
);
});
// fetch the assets
self.addEventListener("fetch", (fetchEvent) => {
fetchEvent.respondWith(
caches.match(fetchEvent.request).then((res) => {
return res || fetch(fetchEvent.request);
})
);
});
// self.addEventListener("activate", async () =>{
// try {
// const options = {}
// const subscription = await self.registration.pushManager.subscribe(options)
// console.log(JSON.stringify(subscription))
// } catch (err) {
// console.log('Error', err)
// }
// })