Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

service worker and client requests 'Cache-control': 'no-cache'

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?

like image 361
Gert Cuykens Avatar asked Dec 10 '25 04:12

Gert Cuykens


1 Answers

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.

like image 109
Gert Cuykens Avatar answered Dec 14 '25 01:12

Gert Cuykens