sw-toolbox
sw-toolbox copied to clipboard
Docs: toolbox.networkFirst should be used if freshness headers are present
If resources are being served with considered cache-control headers, toolbox.networkFirst is probably the correct strategy to use. This probably should be called out in the documentation. (Similarly, the docs should mention that networkFirst (and even networkOnly) will not necessarily force all requests to go over the network.)
For example, if a particular resource is served with cache-control: max-age=3600, then with the networkFirst strategy, this will not actually hit the network until 3600 seconds have elapsed, since fetch() goes through the browser's cache. (I think the networkFirst is equivalent to a stale-while-revalidate value of infinity.)
Yeah, the interaction between service workers, fetch, and the browser's "normal" HTTP cache is a frequent source of confusion for developers.
Would you prefer fetchFirst/fetchOnly/cacheThenFetch etc.?
The existing terminology was, I believe, inspired by @jakearchibald's bible, so mentioning him in to see if he has thoughts.