Suppose the client does this
fetch('example.json', {
headers: {
'Accept': 'application/json',
'Accept-Encoding': 'gzip',
'Cache-control': 'no-cache'
},
method: 'GET'
}).then()
And the server worker does this
self.addEventListener('fetch', (event:any) => {
let request = event.request
if (request.method !== 'GET') return
event.respondWith( caches.match(request)
.then( cachedResponse => {
if (cachedResponse) return cachedResponse
return caches.open(RUNTIME)
.then(cache => fetch(request)
.then(response => cache.put(request, response.clone())
.then(() => response) ))
}))
})
Can I assume caches.match(request) will figure out 'Cache-control': 'no-cache' and just bail out regardless what is stored in the service worker cache?
Feel free to correct me but after googling some more I found this
https://bugs.chromium.org/p/chromium/issues/detail?id=451664#
When I test console.log('SW :', request.headers.get('Cache-control')) the headers seem to be stript out.
I am slowly getting why some browser vendors are hesitant for service workers, it makes the whole caching unintuitive and browser cache already was unintuitive in the first place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With