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

Add more robust SW registration snippet #13

Merged
merged 2 commits into from
May 9, 2017
Merged

Conversation

addyosmani
Copy link
Collaborator

Addresses part of the feedback from #12 with respect to better detecting secure origins are being used. It effectively uses a similar setup to what we originally had for Web Starter Kit.

r @jeffposnick


if ('serviceWorker' in navigator &&
(window.location.protocol === 'https:' || isLocalhost)) {
navigator.serviceWorker.register('service-worker.js')
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's usually a good idea to wrap the register() in a window.onload, as per https://developers.google.com/web/fundamentals/instant-and-offline/service-worker/registration#conclusion

If there's a "better" event to listen for that's exposed as part of the Vue framework, like an event that's fired after all all the custom framework logic has completed, that would be another option to wrap it in.

@addyosmani
Copy link
Collaborator Author

@jeffposnick PTAL. Added the delay to post onload.

@jeffposnick
Copy link
Collaborator

👍

@addyosmani
Copy link
Collaborator Author

Thanks for reviewing!

@addyosmani addyosmani merged commit bc35632 into prototype May 9, 2017
@addyosmani addyosmani deleted the fixes-sw-dev branch May 9, 2017 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants