Añadir 'sw.js'
parent
b7cf493198
commit
b6054eb7fa
@ -0,0 +1,25 @@
|
|||||||
|
async function initCache() {
|
||||||
|
const cache = await caches.open('v1')
|
||||||
|
await cache.addAll([
|
||||||
|
'/',
|
||||||
|
'/index.html',
|
||||||
|
'/app.js'
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
self.addEventListener("install", event => {
|
||||||
|
event.waitUntil(initCache())
|
||||||
|
})
|
||||||
|
|
||||||
|
async function cacheFirst(request) {
|
||||||
|
const resp = await caches.match(request)
|
||||||
|
if (resp) {
|
||||||
|
return resp
|
||||||
|
} else {
|
||||||
|
return fetch(request)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.addEventListener('fetch', event => {
|
||||||
|
event.respondWith(cacheFirst(event.request))
|
||||||
|
})
|
||||||
Loading…
Reference in New Issue