[ServiceWorker] Installing a foreign SW as part of a subresource request (#825)

Site A has an endpoint that takes an image and compresses it. This could run in a SW and use foreign-fetch to make it available offline to others.

However, if site B tries to use this service, there's no way for it to ensure A's service worker is installed.

Ideally it'd fallback to A's server, but that won't work offline.

Site B, could poll site A, waiting for a serviceworker response rather than a server one (assuming they're different). They could do this hack either when the endpoint is needed, or as part of their install step.

This is fragile, as it assumes that the endpoint is going to try and install a SW using a link header, and that the SW install is going to succeed. Either that or the polling happens indefinitely.

Do we want a better solution here?

```js
fetch(url, { swOnly: true });
```

If this is client is controlled by a SW, send to SW. Fail if the SW does not provide a response.

Else, if there's a foreign fetch worker scoped to URL, send to that SW. Fail if the SW does not provide a response.

Else, make a head request to URL. If it provides a link header to install a SW in scope of URL, let that SW install and activate, then send the request to that SW. If no SW installs, fails to install, or does not provide a response, fail.

Do we want to allow something like this?

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/825

Received on Wednesday, 27 January 2016 16:55:10 UTC