-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
SW Sample: Registration with Immediate Replacement #30
Comments
I think you can force a replacement. @paullewis had done something similar during our hack day. |
In theory you can use |
Once w3c/ServiceWorker#518 gets implemented (presumably in M41) we should put together this sample. It won't be possible in M40. |
@jakearchibald just to confirm: w3c/ServiceWorker@c839e33 - that implies that the worker should be able to "take over" (aka, skip waiting) immediately, without any reloads... assuming the correct flag is set. Correct? |
Not quite. It's different to installEvent.replace() in a couple of ways:
Reloading an uncontrolled page will make it controlled, which can be done with location.reload. Do you still need imediate take-over of controlled pages? I'm happy to spec that up too, but it felt like two distinct things (see w3c/ServiceWorker#518 (comment)) |
Yes. At the very least, I want to experiment with it in the context of w3c/ServiceWorker#73 (comment). I can push the controller code ahead of the document, register it as a first thing... and I want it to route all the requests through it on initial load. |
Chrome 43 adds support for I can put something together showing it off in the Chrome 43 timeframe. |
+1 yes please jeff
|
I can see cases where the page would have to communicate directly with the just installed ServiceWorker... forcing the page to refresh would seriously hamper the usability of the page. For example, in my SW library I am creating a script which sites can add to their page, passing the urls of assets to cache as parameters: <script src="/upup.min.js"></script>
<script>
UpUp.start({
'content-url': 'offline.html',
'assets': ['/img/logo.png', '/css/style.css', 'headlines.json']
});
</script> Since the assets to cache can't be hard coded in the install event, they need to be posted as a message. This leaves the site with two options, either refresh the page (blegh), or only cache content the next time a user visits the page. I was able to solve this by accessing the ServiceWorker using the ServiceWorkerRegistration object, and posting a message to it directly after install. I've posted a sample of how this can be done in #94 |
Jeff, I could have sworn that claim() worked for me in M42. That might just have Can you please clarify so that I can make sure MDN is correct? Joe Medley | Technical Writer | [email protected] | 816-678-7195 On Tue, Mar 24, 2015 at 7:46 AM, Jeffrey Posnick [email protected]
|
Sorry for the confusion—@jpmedley, you're right that I'll add a sample to show off this functionality and close this issue. |
It should demonstrate standard registration with a technique for immediately elevating the installing SW to be the controlling SW. (I think this would entail forcing the page to refresh, but it would be good to confirm the best practice first.)
The text was updated successfully, but these errors were encountered: