This commit is contained in:
Filipe Medeiros 2021-12-04 13:50:42 +00:00
parent efe6fd1a03
commit f5fdc37fc3

View file

@ -16,14 +16,16 @@ self.addEventListener('install', event => {
})
self.addEventListener('fetch', async event => {
let resp = await caches.match(event.request)
if (resp === undefined) {
resp = await fetch(event.request)
event.waitUntil(async () => {
let resp = await caches.match(event.request)
if (resp === undefined) {
resp = await fetch(event.request)
if (event.request.method === 'GET') {
const cache = await caches.open('v1')
cache.put(event.request, resp.clone())
if (event.request.method === 'GET') {
const cache = await caches.open('v1')
await cache.put(event.request, resp.clone())
}
}
}
event.respondWith(resp)
return event.respondWith(resp)
})
})