sw-redux icon indicating copy to clipboard operation
sw-redux copied to clipboard

Smarter cache updates

Open adregan opened this issue 8 years ago • 0 comments

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.

adregan avatar Mar 25 '16 20:03 adregan