sw-redux
sw-redux copied to clipboard
Smarter cache updates
Currently, the update mechanism for the cache is keyed to a service worker version change. Anytime the service worker is rebuilt, I have a script that increments the version. As such, the new worker installs and creates a new cache and destroys the old cache. Changes to static assets are then displayed on refresh.
However, incrementing the service worker's version isn't necessarily the best way to update and asset (imagine needing to rebuild the worker because you cropped an image). The fetch event needs to be smarter:
- load the page from cache
- in the background, check to see if any of the cached files have changed (if there is a connection)
- when changes are found, update the cached version
I'll explore whether or not there is any benefit to making HEAD
requests, but due to unknown server support, will probably stick to making the request and comparing the cached version to the downloaded version.