问题
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) ?
回答1:
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.
来源:https://stackoverflow.com/questions/42466473/if-you-are-using-service-workers-do-you-still-need-cache-control-headers