Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Add the ability for any spec to have a service worker #53

Merged
merged 2 commits into from
Jul 18, 2017

Conversation

domenic
Copy link
Member

@domenic domenic commented Apr 4, 2017

Part of whatwg/meta#3. This allows any standard using the shared deploy script to automatically get a service worker generated, which delegates all of its logic to a shared file on resources.whatwg.org. It allows room for future expansions of the deploy script to include extra resources.

This still requires registering the generated service worker in each spec's HTML, however.


On top of #52. To get this working on specs using the new deploy script (e.g. URL), include the following at the bottom of your page:

<script>
"use strict";
if ("serviceWorker" in navigator) {
  navigator.serviceWorker.register("/service-worker.js");
}
</script>

We could in the future add that our Bikeshed template, once all specs are on the new deploy script (whatwg/meta#11).

I tested this locally, kinda (without the shortname inference), but as usual it'd be best to merge this and try it on specs when multiple people are online.

@domenic
Copy link
Member Author

domenic commented Apr 4, 2017

@jakearchibald pointed out a potentially deadly problem with this, which is that as implemented now, no browser will ever update this service worker, even if we update standard-service-worker.js. Since the actual service worker is byte-for-byte identical, it doesn't bother revalidating importScripts()-ed scripts like standard-service-worker.js.

This is fixed in the spec but not implementations.

We could work around this in the future by writing out a "version" comment in the deploy script if necessary, e.g. add a line like // v2. I guess it's OK as long as we remember to do that (for as long as the browsers don't implement importScripts() checking).

@zcorpan
Copy link
Member

zcorpan commented Apr 6, 2017

Could the comment be automated somehow (maybe include commit hash)?

@domenic
Copy link
Member Author

domenic commented Apr 7, 2017

Hmm, that might work... to be clear, it'd be the commit hash of standard-service-worker.js from resources.whatwg.org. I wonder how to get that without too much code...

Part of whatwg/meta#3. This allows any standard using the shared deploy script to automatically get a service worker generated, which delegates all of its logic to a shared file on resources.whatwg.org. It allows room for future expansions of the deploy script to include extra resources.

This still requires registering the generated service worker in each spec's HTML, however.
@domenic
Copy link
Member Author

domenic commented Jun 22, 2017

I've updated this to add a version comment and be rebased on master.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any obvious problems, but I'm not as familiar with these things as @jakearchibald is. Happy for you to give this a try though.

@domenic domenic merged commit bd7900e into master Jul 18, 2017
@domenic domenic deleted the shared-serviceworker branch July 18, 2017 19:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants