You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
504 B
JavaScript
25 lines
504 B
JavaScript
|
3 years ago
|
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))
|
||
|
|
})
|