-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathserviceworker.js
More file actions
38 lines (35 loc) · 987 Bytes
/
serviceworker.js
File metadata and controls
38 lines (35 loc) · 987 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const staticApp = "CGPA_Result_Forecaster-v1";
//cache the assets that will be needed offline
const assets = [
"/",
"/index.html",
"/css/style.css",
"/css/style.css.map",
"/sass/_base.scss",
"/sass/style.scss",
"/sass/_medium.scss",
"/main.js",
"images/calculator-logo-72.png",
"images/calculator-logo-96.png",
"images/calculator-logo-124.png",
"images/calculator-logo-144.png",
"images/calculator-logo-152.png",
"images/calculator-logo-512.png",
"images/calculator-logo.png",
];
/*Attach an event listener to the service worker processor(self) to listen to the install event */
self.addEventListener("install", installEvent => {
installEvent.waitUntil(
caches.open(staticApp).then(cache => {
cache.addAll(assets);
})
);
});
//fetch cache
self.addEventListener("fetch", fetchCache => {
fetchCache.respondWith(
caches.match(fetchCache.request).then(response => {
return response || fetch(fetchCache.request);
})
);
});