morbidick / serviceworker-helpers

Display a toast on available service worker update
9 stars 1 forks source link

Question: is this compatible with PSK out of the box? #6

Open chwzr opened 6 years ago

chwzr commented 6 years ago

I know its not the propper place to ask questions, but is this element compatible and working out of the box with the Polymer starter Kit Service-Worker implementation?

At mine it does not trigger the updatefound event, even if I change something at sw-precache-config.js or directly at the generated service-worker.js... e.g. chaning the cacheId from 001 to 002 and then build + deploy the changes. Nothing happens on page reload.. but when I go to dev tools application tab, and click update on the service worker, the toast shows up, and then on page reload the new content shows up..

I guess the boilerplate for registering the service worker (inside index.html of the PSK) is not enough?

Maybe changing documentation if some more lines of code is needed to fire the updatefound event?

Kind Regards,

Chwzr

chwzr commented 6 years ago

I've found out that its not an issue with the service worker registering or the PSK implementation or your Element: For those hosting on Firebase, the Cache-Control header cache-control:max-age=3600 is set to one hour, so for apps in development you can use this snippet inside your firebase.json's hosting Object to disable caching for the service worker at all:

"headers": [{
  "source" : "service-worker.js",
  "headers" : [{
    "key" : "Cache-Control",
    "value" : "max-age=0"
  }]
}]

In a production environment, however, one should rethink the importance of the app's up-to-dateness for the sake of LIGHTSPEED page load times and adjust it back to one hour ;-)

Maybe its worth a little line in the documentation, but it's your choice! Please close this issue. Thx for this awesome element!

morbidick commented 6 years ago

Oh yeah good find, thats a point i struggled with too and would be a good addition to the readme (since we already have a section on registering an sw). I'll leave this open to track the issue until its added to the docs.

veith commented 6 years ago

Why do you use service worker during development?

The polymer starter kit service-worker.js says: 'Service worker disabled for development, will be generated at build time.'

chwzr commented 6 years ago

Yes but at development time you also have to test your build (with the service worker which is generated at build time, not the dummy one in the source folder which only logs this line)

And when its critical for your app to be up to date, you also need a fresh service worker with fresh document hashes to purge the old documents in cache ;)