-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Feature request: Provide a way for an AMP document to request installation of a Service Worker #586
Comments
Yep, the SW root script needs to be fetched from the origin itself. That said, you can pull things from other origins using |
In case it's useful: I'm thinking about a similar use case for a sample that I'm putting together. I wasn't sure about the cleanest way to register a top-level SW from within an article page that might be served a few levels down in the URL hierarchy. After some experimentation, I ended up with this approach that seems to work: // Don't bother creating the <iframe> if we're already controlled by a service worker.
if ('serviceWorker' in navigator && !navigator.serviceWorker.controller) {
var iFrame = document.createElement('iframe');
iFrame.src = '/register-service-worker.html';
iFrame.style.display = 'none';
document.body.appendChild(iFrame);
} Within |
@slightlyoff @jeffposnick So https://foo.com/bar/ cannot install https://foo.com/serviceworker.js? In that case the iframe is fine. I did not want to go towards installing service workers for the "home origin" when servings AMPs from a proxy domain although that would be an interesting future addition. |
Right, by default, w3c/ServiceWorker#468 (comment) has some background, along with a reference to a |
As it turns out, I'm giving out bad advice, and was implementing things incorrectly in my own project. https://foo.com/bar/ can install https://foo.com/serviceworker.js without requiring the |
Ah, that is what I though. Great. Makes this much simpler :) Can https://bar.com/ install https://foo.com/serviceworker.js ? The modern equivalent of cookie dropping :) |
Something like
should do it.
The Service Worker would only be installed when the document is loaded from the respective origin or the worker (right?) otherwise it is a noop.
CC @slightlyoff
The text was updated successfully, but these errors were encountered: