-
Notifications
You must be signed in to change notification settings - Fork 1
/
serviceworker.js
40 lines (32 loc) · 928 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 cachea = "HVHCache-v1";
list = []
var appshellfiles = [
// pages can be added here for caching
'/index.html',
'/home.html',
'/counterPage.html',
'/github.html',
'/info.html',
'/tab.min.js', '/save.min.css', '/manifest.json', '/logo.png',
'fonts/MatSymbolsRounded.woff2', 'fonts/Poppins-Medium.ttf'
]
appshellfiles = []
self.addEventListener("install", e => {
e.waitUntil((async () => {
const cache = await caches.open(cachea);
await cache.addAll(appshellfiles);
})());
});
self.addEventListener("activate", event => {
console.log("Service worker activated");
});
const cacheFirst = async (request) => {
const responseFromCache = await caches.match(request);
if (responseFromCache) {
return responseFromCache;
}
return fetch(request);
};
self.addEventListener("fetch", (event) => {
event.respondWith(cacheFirst(event.request));
});