-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice worker.js
More file actions
24 lines (22 loc) · 974 Bytes
/
service worker.js
File metadata and controls
24 lines (22 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
self.addEventListener("install",e =>{
// self keyword refers to the global scope of the service worker itself
//Installation of PWA
console.log("Instalation started !!");
//caching of the data
e.waitUntil(
caches.open("static").then(cache =>{
//files to cached when there is slow or no internet
return cache.addAll(["./", "./css/style.css","./img/logo-512x512.png",
"./img/logo-192x192.png","./js/script.js"]);
})
);
console.log("Installation done");
});
self.addEventListener("fetch",e =>{
e.respondWith(
caches.match(e.request)
.then(response =>{
return response || fetch(e.request); // to check if data is availble in cache than respond from cache db storage otherwise go to fetch (make a network call to get the data) "Cache-First" strategy
})
)
});