From f5fdc37fc3cd3bb1c74d8c14961873c52f4702aa Mon Sep 17 00:00:00 2001 From: Filipe Medeiros Date: Sat, 4 Dec 2021 13:50:42 +0000 Subject: [PATCH] fix: sw --- public/sw.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/public/sw.js b/public/sw.js index 80a8563..c92243c 100644 --- a/public/sw.js +++ b/public/sw.js @@ -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) + }) })