preact-cli
preact-cli copied to clipboard
Service Worker loaded from CDN
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 https://github.com/developit/preact-cli/pull/323
What is the expected behaviour?
sw.js
must be loaded from the base domain. See https://github.com/w3c/ServiceWorker/issues/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
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"?
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');
can we re-open this ticket? I am encountering the same issue. the suggestion from @developit might work
can you please try this with the latest rc?
@prateekbh , just tested it with latest rc. still being compiled as n.p+"sw.js"
is this deployed somewhere?
a ok this makes sense. I can take a look at it
@prateekbh , i can create a PR, if it's ok. not sure if there is a standard guide that i need to follow though
@prateekbh , does the current npm run test
command works? i am getting error when running it. tried on master
branch as well
Your cdn should be in the same tld, ideally your first party origin (if you don't use SSR which makes it harder)