Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A header-based SW installation #685

Closed
jungkees opened this issue Apr 22, 2015 · 16 comments
Closed

A header-based SW installation #685

jungkees opened this issue Apr 22, 2015 · 16 comments

Comments

@jungkees
Copy link
Collaborator

It's been discussed as part of the navigator.connect() and decided to be proposed as an extension to SW API (v2).

Assuming a communication between a client SW and a service SW is enabled through the efforts in navigator.connect()'s persistent channel messaging and the fallThrough requests proposal, the client SWs would need to use readily installed service SWs whenever possible.

Here's a proposal to allow services to install their SWs using HTTP headers when any of their resources are requested: https://github.com/mkruisselbrink/navigator-connect/blob/gh-pages/explainer.md#mommy-where-do-service-workers-come-from

@jakearchibald
Copy link
Contributor

On #684 I pitch the idea of:

// https://foo/sw.js
self.oninstall = event => {
  event.waitUntil(
    event.registerExternal('//font-service/sw.js')
  );
};

This would only require '//font-service/sw.js to have a header indicating scope. It doesn't allow page/subresource headers to register a ServiceWorker, but is there any benefit in doing this?

@mkruisselbrink
Copy link
Collaborator

I don't really like the idea of having in this case the foo service worker specify the exact path to the font-service service worker script. It seems to me that conceptually the script URL of a service worker should be an implementation detail of that site, and not part of its public API. But maybe that's just my mental model being wrong.

And specifically for the fonts usecase, allowing subresource headers to register a ServiceWorker is what makes this all work transparently. I'm not entirely sure what we would gain by requiring any website that wants to benefit from a fonts service worker to explicitly specify this. Shouldn't websites that don't have their own service worker also be able to benefit from services they rely on having service workers?

@jakearchibald
Copy link
Contributor

allowing subresource headers to register a ServiceWorker is what makes this all work transparently

I don't think it does. Your site should work offline after install. Since font requests happen when the font is requested, you could end up with a serviceworker installing without a request to the font service.

Shouldn't websites that don't have their own service worker also be able to benefit from services they rely on having service workers?

Hmm, yeah, that would be nice.

@KenjiBaheux
Copy link
Collaborator

@jungkees I lost track of this feature. Was there any other relevant discussion or pushback?

We are discussing with partners and for some a header based SW installation is a must have (e.g. Google Fonts: not a destination website, integration point being a link rel stylesheet)

@jungkees
Copy link
Collaborator Author

I think it has just not been discussed for a while. I added this issue to the f2f agenda. If there's not enough time to cover this, I'll at least share it with the attendees so we can follow up on the discussion.

@jakearchibald
Copy link
Contributor

F2F:

Header: Link: </sw.js>; rel=serviceworker; scope=/
But also element: <link rel="serviceworker" scope="/" href="/sw.js">

@ehsan
Copy link

ehsan commented Jan 27, 2016

@mkruisselbrink
Copy link
Collaborator

@annevk How would I go about actually spec-ing this?

The <link rel= part is probably relatively straight forward. Similar to how specs like the web app manifest specified a new link type, we can do the same in the service worker spec for the new serviceworker link type. Although I'm not sure how we'd add the new 'scope' attribute to the link tag without changing the HTML spec directly?

But what do we do about the Link header. https://www.w3.org/wiki/LinkHeader makes it sound like it isn't actually specified anywhere (other than some old version of HTTP 1.1). So how/where should Link be specified?

@KenjiBaheux
Copy link
Collaborator

Perhaps, following how it's done for preload would work?
http://w3c.github.io/preload/
cc/ @igrigorik

@KenjiBaheux
Copy link
Collaborator

@mkruisselbrink
Copy link
Collaborator

Ah yes, thanks. I must have not been searching for the right things. That looks helpful for inspiration.

@annevk
Copy link
Member

annevk commented Jan 29, 2016

The header is defined in https://tools.ietf.org/html/rfc5988. And yes, we'd have to modify the HTML standard to properly define the element.

@sideshowbarker
Copy link
Contributor

FYI I wrote a PR for adding <link rel=serviceworker> and scope, workertype, and usecache to the HTML spec: whatwg/html#2356

@annevk
Copy link
Member

annevk commented Mar 31, 2017

Were tests written for this as well?

@mkruisselbrink
Copy link
Collaborator

Yes, I believe the only things left to do here are I think the cleanup from #1098 and IANA registering the new link relation type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants