NYPL-Simplified / webpub-viewer

8 stars 4 forks source link

Service worker doesn't always update in background #109

Open leonardr opened 7 years ago

leonardr commented 7 years ago

I'm not going to do a great job of summarizing this issue, but here we go.

There are situations where the service worker tries to fetch a new version of a resource, but it isn't able to. In this situation it just stops trying to fetch the new version, even if the browser user does a hard refresh. This leads to old content being displayed even though HTTP requests are apparently going out and coming back with 200 response codes.

A simple solution is to stop using service workers and fall back to application cache. This will eventually stop working, but it should be okay in the short term.

A proper solution depends on figuring out when the service worker gives up on its background request.

leonardr commented 7 years ago

Amy's recommendation is to take out service worker for now.

aslagle commented 7 years ago

The way the service worker is currently set up it will serve a resource immediately from cache, then try to fetch an update and cache it for the next time. However, the browser may terminate the service worker before the update finishes.

Another problem is that the service worker currently handles every request on the domain. It should probably be limited to urls that were explicitly cached.

This repository currently has two Cacher implementations - ApplicationCacheCacher, and ServiceWorkerCacher which falls back to ApplicationCacheCacher when the browser does not support service workers. If the current service worker setup causes problems for an implementation, it can use the ApplicationCacheCacher instead.