Is there any use-case where the use of cache-control
headers should be preferred over Service Workers? Is there any benefit using both of them (apart from the fact the SW are not cross-browser supported) ?
Absolutely. HTTP cache, which is controlled by HTTP cache headers sits between the network and the service worker. All fetch
requests initiated from the service worker still use HTTP cache.
Let's say you have a script with long max-age
. Most Service Workers repopulate their caches every time they are installed, which is to say, every time something/anything changes in the service worker script. However, if HTTP cache headers are properly configured many resources to be included in Service Worker cache will be still present in HTTP cache and can be fetched without involving the network.
Properly configured HTTP headers are also essential for intermediary caching proxies (CDNs) to work properly. Proxies do not know anything about Service Worker and its caches.
More on this in Caching best practices & max-age gotchas by Jake Archibald.
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