-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
27 lines (26 loc) · 1021 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
const cachename = 'vid2'
const assets = ['/vidplayer/','/vidplayer/index.html','/vidplayer/assets/main.js',"/vidplayer/assets/icons/fontawesome-all.min.css","/vidplayer/assets/materialize.min.css","/vidplayer/assets/webfonts/fa-solid-900.woff2","/vidplayer/assets/webfonts/fa-solid-900.woff"]
self.addEventListener('install',e=>{
e.waitUntil(
caches.open(cachename)
.then(cache=>cache.addAll(assets))
.then(suc=>console.log(suc,'success'))
.catch(err=>console.log(err,'error'))
)
})
self.addEventListener('activate',e=>{
e.waitUntil(
caches.keys().then(keys=>{
return Promise.all(
keys.filter(key=>key!==cachename).map(key=>caches.delete(key))
)
})
)
})
self.addEventListener('fetch',e=>{
e.respondWith(async function() {
const cachedResponse = await caches.match(e.request);
if (cachedResponse) return cachedResponse;
return fetch(e.request);
}());
})