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

Service Workers #25

Closed
flasaracina opened this issue Aug 9, 2019 · 14 comments
Closed

Service Workers #25

flasaracina opened this issue Aug 9, 2019 · 14 comments

Comments

@flasaracina
Copy link

Hello!
I am using servor for a web application I am building and I was wondering if there is an option to set up the service-worker-allowed for the site service worker.

Thanks in advance

@lukejacksonn
Copy link
Owner

Hey, apologies for the late reply. I have been on vacation 🏖

This sound reasonable. I didn't know service-worker-allowed was a thing tbh! We could add that header when JS files are on their way out?

@flasaracina
Copy link
Author

flasaracina commented Sep 4, 2019

oh, no worries! Hope you had a great time! :)

service-worker-allowed header should be only set when serving a service worker file, because you could have multiple service workers for a single "website". I think it would be nice if we could configure it somehow.

I was thinking about something along the lines of:

servor ./ ./index.html 3000 3001 --no-reload --sw-scopes ./sw.js=/ ./sample/sw.js=/

or something like that. I know you can come up with a clever idea on how to configure that header per service-worker path.

Thank you very much and keep up with the good work! It's much appreciated

@lukejacksonn
Copy link
Owner

Humm, that seems a little more involved.. would putting it on every request break the site or service worker?

@flasaracina
Copy link
Author

flasaracina commented Sep 6, 2019

It will not break anything, I think. That header is there only to tell the browser how to setup the service worker. There is only one real problem I see, that is you can have multiple service workers on a site (with a unique scope each). If you just spit that header out on every request, It'll be impossibile for the developer to customize multiple service workers behaviour.

@lukejacksonn
Copy link
Owner

Ok, do you think a service worker file naming convention (like *.sw.js) could work?

@flasaracina
Copy link
Author

I think it will. But how do you customize the value of that header per service worker served?

@lukejacksonn
Copy link
Owner

This isn't really something I have looked into too deeply.. perhaps you could point me in the right direction of some good examples/documentation for this kind of setup?

@flasaracina
Copy link
Author

Ok, no problem. Google made a nice guide to how service workers work.
You can find it here:
Introduction to Service Worker

In the introduction they also mention the header (it's a very simple thing once you got the basics of how they need to be configured), but the link points to the spec here:

Service Worker Script Http Response

@lukejacksonn
Copy link
Owner

So.. yesterday I tried adding a service worker to a site I was developing on using servor and it seemed to work just fine.. what issue were/are you actually experiencing?

@flasaracina
Copy link
Author

flasaracina commented Sep 13, 2019

Try to add a service worker file in a subfolder and try to give it / as a scope (the whole site)

It shouldn't work because the scope of a service worker MUST be of the same folder hierarchy or lower. If your service worker file resides in a subfolder, it cannot handle calls that originate from scripts that reside in a higher folder hierarchy (let's say root, for example)

@lukejacksonn
Copy link
Owner

Ahhh.. I see! That makes sense. I have never had more than one service worker or wanted them to have different scopes. Seems like it would be hard to input that kind of config on CLI 🤔

@flasaracina
Copy link
Author

I see. What do you think about the sample configuration I come up with in my second comment
here ?

Do you think it's doable as a starter? Just to have such functionality?

Thank you for your time ;)

@lukejacksonn
Copy link
Owner

I think you could almost definitely set this up in a fork! Check out this PR which adds cors headers https://github.com/lukejacksonn/servor/pull/3/files it might give you some clues as where to get started.

@lukejacksonn
Copy link
Owner

Hey @flasaracina did you figure out a nice solution to this issue? I am going to close here as it has been inactive for a while and I still haven't come across any issues with service workers myself (probably because I am just using them at the root of my project).

Happy to discuss again though if you have found a nice workaround!

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

No branches or pull requests

2 participants