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 Worker loaded from CDN #591

Open
florianmutter opened this issue Jun 21, 2018 · 10 comments · May be fixed by #1328
Open

Service Worker loaded from CDN #591

florianmutter opened this issue Jun 21, 2018 · 10 comments · May be fixed by #1328

Comments

@florianmutter
Copy link

florianmutter commented Jun 21, 2018

Do you want to request a feature or report a bug?
Report a Bug

What is the current behaviour?
sw.js is loaded from a CDN if a CDN is set in the webpack publicPath. This is forbidden:
Failed to register a ServiceWorker: The origin of the provided scriptURL ('https://yourcdn.net') does not match the current origin ('https://yourapp.com').

If the current behaviour is a bug, please provide the steps to reproduce.
Add the following snippet to preact.config.js:

config.output.publicPath = '//youcdn.net/';

It seems this was introduced in #323

What is the expected behaviour?
sw.js must be loaded from the base domain. See w3c/ServiceWorker#940

Please mention other relevant information.

  • Node version: v6.10.3
  • npm version: 3.10.10
  • Operating system: macOS
  • CLI version: 2.2.1
  • Browser: Chrome 67.0.3396.87
@fedemar
Copy link

fedemar commented Jul 23, 2018

Any idea on how to get around this?
Maybe using a plug in to replace the compiled bundle from n.p+"sw.js" to "/sw.js"?

@developit
Copy link
Member

Hmm - this is an odd one. It might be worth us adding an option to define SW_PATH?

navigator.serviceWorker.register((SW_PATH || __webpack_public_path__) + 'sw.js');

@kencanak
Copy link

can we re-open this ticket? I am encountering the same issue. the suggestion from @developit might work

@prateekbh
Copy link
Member

can you please try this with the latest rc?

@kencanak
Copy link

@prateekbh , just tested it with latest rc. still being compiled as n.p+"sw.js"

@prateekbh
Copy link
Member

is this deployed somewhere?

@prateekbh
Copy link
Member

a ok this makes sense. I can take a look at it

@prateekbh prateekbh reopened this Jul 16, 2020
@prateekbh prateekbh self-assigned this Jul 16, 2020
@kencanak
Copy link

@prateekbh , i can create a PR, if it's ok. not sure if there is a standard guide that i need to follow though

kencanak pushed a commit to kencanak/preact-cli that referenced this issue Jul 16, 2020
- introduced new cli args to define swPath, default would be '/'.
- decoupled from using webpack public path, better to be implicit
kencanak pushed a commit to kencanak/preact-cli that referenced this issue Jul 16, 2020
… cdn issue

- introduced new cli args to define swPath, default would be '/'

- decoupled from using webpack public path, better to be implicit
kencanak pushed a commit to kencanak/preact-cli that referenced this issue Jul 16, 2020
kencanak pushed a commit to kencanak/preact-cli that referenced this issue Jul 16, 2020
@kencanak kencanak linked a pull request Jul 16, 2020 that will close this issue
@kencanak
Copy link

@prateekbh , does the current npm run test command works? i am getting error when running it. tried on master branch as well

@ForsakenHarmony
Copy link
Member

Your cdn should be in the same tld, ideally your first party origin (if you don't use SSR which makes it harder)

kencanak pushed a commit to kencanak/preact-cli that referenced this issue Jul 30, 2020
… of __webpack_public_path__ if it begins with http protocol, set it blank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants