-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Service workers #463
Service workers #463
Conversation
|
||
const url = new URL(request.url); | ||
|
||
if (url.protocol === 'https:' || location.hostname === 'localhost') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might reverse this to reduce indentation:
if (url.protocol !== 'https:' && location.hostname !== 'localhost') {
return;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed my mind about onFetch
, and I think respondWith
reads better as an if/else chain (since otherwise you have to do an early return as well as respondWith
, but yeah, this would have been better
We've had issues in Sapper with the |
Can remove
Might need to slightly update the docs: |
Can you elaborate? |
Good catch, removed I had a change of heart about |
Here are the Sapper issues: sveltejs/sapper#1538 and sveltejs/sapper#1441. Not sure there's too much to be aware of here except that if we want to support |
Ah ok. That should work just fine, since |
Closes #10.
One thing I realised: this gets a little tricky when
paths.assets
is specified, since service workers are scoped to their own parent 'directory'. The simplest solution, at least for now, is just to disable service workers if that option is specified.Not quite sure how to test for this. I added a sample service worker to
examples/sandbox
though, and confirmed that it works offline. Would just need a compliant manifest.json to be a valid PWA.