GoogleChromeLabs / sw-toolbox

[Deprecated] A collection of service worker tools for offlining runtime requests
https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-sw
Apache License 2.0
3.61k stars 331 forks source link

Docs: toolbox.networkFirst should be used if freshness headers are present #136

Open ithinkihaveacat opened 8 years ago

ithinkihaveacat commented 8 years ago

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.)

jeffposnick commented 8 years ago

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.