webhintio.github.io icon indicating copy to clipboard operation
webhintio.github.io copied to clipboard

Re-add service worker

Open molant opened this issue 8 years ago • 3 comments

Because the service worker is in the root right now we are not cache busting it nor adding the right cache-control header. We should find a way to do this.

molant avatar Jan 19 '18 00:01 molant

@molant The cache-control header is set to no-cache in the sonarwhal-worker. What's the "right" cache-control header value that it should be changed to? It doesn't seem right to me to set a max-age for the service worker since the content is mutable.

qzhou1607-zz avatar Feb 05 '18 18:02 qzhou1607-zz

I think that if you move the scripts to /static/scripts the gulp task should take care of updating the file names and the html that points to it.

molant avatar Feb 05 '18 18:02 molant

Here's a couple of pointers, I hope they'll be of help if/when you decide to reintroduce service workers again:

For webhint-worker.js:

  • Should live in the root folder, enables full scope of the site.

  • Don't set a hash in the url, it may cause issues (sw always updates if the file is modified anyways): → https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#avoid_changing_the_url_of_your_service_worker_script

  • If usage of the Cache-Control header is still desired (since the Chrome 68 changes, see link provided below) you will need to opt-in by setting updateViaCache to the preferred value. If that is the case, no-cache should suffice in making sure content is fresh, but yes the SW will incur a network request every navigation. → https://developers.google.com/web/updates/2018/06/fresher-sw

For sw-reg.js:

  • Can be placed anywhere, just point the registration to /webhint-worker.js.

Malvoz avatar Sep 13 '18 16:09 Malvoz