简体   繁体   中英

If you are using Service Workers do you still need cache-control headers?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM