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

Allow relative sw.js registration #111

Closed
zorn-v opened this issue Mar 28, 2018 · 11 comments
Closed

Allow relative sw.js registration #111

zorn-v opened this issue Mar 28, 2018 · 11 comments

Comments

@zorn-v
Copy link

zorn-v commented Mar 28, 2018

Currently it is imposible. But in ember if no rootURL is defined assets inserted with relative url.
I think "last resort" should be '' but not '/' here https://github.com/DockYard/ember-service-worker/blob/master/index.js#L144

PS. I have a project with no deterministic root url. Just imagine a 'skel' with symlinks to it, and logic depends of result url.
Anyway I implemented SW by my own (with 'scope':'./'), but it is big mistake to restrict relative urls...

@villander
Copy link
Contributor

villander commented Mar 30, 2018

@zorn-v use navigator.serviceWorker.register('/sw.js') it's works as './'

@zorn-v
Copy link
Author

zorn-v commented Mar 31, 2018

Nope.
Imagine that my index.html in https://example.com/subdir/another/
If I register as you say, sw.js will try to load from https://example.com/sw.js (but it is not there)

But navigator.serviceWorker.register('sw.js', {scope: './'}) will register https://example.com/subdir/another/sw.js with scope https://example.com/subdir/another/

@deepflame
Copy link

deepflame commented Apr 16, 2018

Our case sounds similar to yours.

We use the lightning deployment strategy and host our assets on a CDN. Now when we serve the index.html './sw.js' is not found as this is on the CDN.
If I change now the rootUrl in the config the scope points to the CDN but I would like it to remain '/'.

So we should be able to have a different configuration option for scope and URL of the sw.js file:
https://github.com/DockYard/ember-service-worker/blob/master/service-worker-registration/index.js#L7

Hmm, but it seems that we cannot specify different subdomains due to security issues...

@ghost
Copy link

ghost commented Apr 16, 2018

Service Workers need to be hosted on the same domain. CDN's are not allowed.
You'll need to adjust your lightning deploy system to deploy sw.js to the same box as the index.html file.

@deepflame
Copy link

Thanks for the clarification @martndemus . Maybe this is something for the docs as well?

@ghost
Copy link

ghost commented Apr 16, 2018

I'd rather not go into the rabbit hole of repeating general SW knowledge.

@sescobb27
Copy link

There is some work in progress being made in ember-cli-deploy-lightning-pack, for now, we can follow the recommendations mentioned in this issue ember-cli-deploy/ember-cli-deploy-lightning-pack#46 to deploy sw.js to the same host as the index.html

@achambers
Copy link

Another approach I have used in the lighting strategy, instead of hosting the service worker in the same place as index.html, is to simply have the lightning server forward the request for sw.js to the CDN

@eshtadc
Copy link
Contributor

eshtadc commented Dec 14, 2018

Good general information in here but nothing actionable that I see so closing this out.

@eshtadc eshtadc closed this as completed Dec 14, 2018
@zorn-v
Copy link
Author

zorn-v commented Dec 14, 2018

but nothing actionable

Really ? Remove slash and add ONE DOT with no drawbacks and many buns ?
Ok, you wish.

@eshtadc
Copy link
Contributor

eshtadc commented Dec 19, 2018

Hi there @zorn-v. It's quite possible that I've missed something here, so if you'd like to further explain - or submit a PR with your suggestion I'd be happy to look further and/or re-open this issue.

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

6 participants