Browse Source

Always reload when making network request

master
Kenneth Bruen 1 year ago
parent
commit
0afe31fba3
Signed by: kbruen
GPG Key ID: C1980A470C3EE5B1
  1. 15
      sw.js

15
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

Loading…
Cancel
Save