From 0afe31fba3c064270f68360a28db272137193bb1 Mon Sep 17 00:00:00 2001 From: Dan Cojocaru Date: Thu, 2 Nov 2023 05:17:48 +0100 Subject: [PATCH] Always reload when making network request --- sw.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sw.js b/sw.js index ea00d9f..45fa087 100755 --- a/sw.js +++ b/sw.js @@ -1,4 +1,4 @@ -const VERSION = 'v17' +const VERSION = 'v18' const CACHE_FIRST = [ // Root @@ -140,8 +140,11 @@ const cacheFirst = async ({ request, preloadResponsePromise, refreshAnyway }) => console.log('[cf] using cache response; refreshing anyway but returning cache', responseFromCache); ((async () => { try { - const response = await fetch(request) + const response = await fetch(request, { + cache: 'reload', + }) if (response.ok) { + console.log('[cf] after cache response, got and cached network response') await putInCache(request, response) } } @@ -174,7 +177,9 @@ const cacheFirst = async ({ request, preloadResponsePromise, refreshAnyway }) => } // Next try to get the resource from the network - const responseFromNetwork = await fetch(request) + const responseFromNetwork = await fetch(request, { + cache: 'reload', + }) // response may be used only once // we need to save clone to put one copy in cache // and serve second one @@ -212,7 +217,9 @@ const networkFirst = async ({ request, preloadResponsePromise }) => { let responseFromNetwork let errorFromNetwork try { - responseFromNetwork = await fetch(request) + responseFromNetwork = await fetch(request, { + cache: 'reload', + }) } catch (e) { responseFromNetwork = null