Skip to content

Instantly share code, notes, and snippets.

@madneal
Created April 22, 2017 05:27
Show Gist options
  • Save madneal/c32bba63dc2e493713a26b3794dbb1ce to your computer and use it in GitHub Desktop.
Save madneal/c32bba63dc2e493713a26b3794dbb1ce to your computer and use it in GitHub Desktop.
toolbox.precache() will add one or more URLs to a cache when the service worker is installed, but it won't take any steps to make sure that those URLs are kept up to date. So, for instance, if you call toolbox.precache(['index.html']), it will add an entry for index.html to your runtime cache when the service worker is installed, but there is nothing that will automatically update that entry when index.html changes. sw-toolbox also does not set up any routes or handlers to serve that cached response by default. It's up to you, as a developer, to set up a route that will match requests for index.html and use an appropriate handler (and hopefully not use cacheFirst, or else index.html will never be updated).
In contrast, sw-precache integrates with your build process, and takes care of detecting when any of your local assets, like index.html, have changed. When something does change, it will automatically update the cached entry for you. It will also set up routes with an appropriate handler to match requests for those precached assets.
sw-toolbox is a great tool for scenarios in which runtime caching is needed, but sw-precache is preferable for local assets that can be versioned and are small enough to be precached.
@madneal
Copy link
Author

madneal commented Apr 22, 2017

toolbox.precache() will add one or more URLs to a cache when the service worker is installed, but it won't take any steps to make sure that those URLs are kept up to date. So, for instance, if you call toolbox.precache(['index.html']), it will add an entry for index.html to your runtime cache when the service worker is installed, but there is nothing that will automatically update that entry when index.html changes. sw-toolbox also does not set up any routes or handlers to serve that cached response by default. It's up to you, as a developer, to set up a route that will match requests for index.html and use an appropriate handler (and hopefully not use cacheFirst, or else index.html will never be updated).

In contrast, sw-precache integrates with your build process, and takes care of detecting when any of your local assets, like index.html, have changed. When something does change, it will automatically update the cached entry for you. It will also set up routes with an appropriate handler to match requests for those precached assets.

sw-toolbox is a great tool for scenarios in which runtime caching is needed, but sw-precache is preferable for local assets that can be versioned and are small enough to be precached.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment