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

人盡茶涼 提交于 2021-01-02 19:23:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!