service-worker script wont load from non-root path
See original GitHub issuecode-server
version: 1.939-vsc1.33.1- OS Version: irrelevant
Description
We are running code-server
behind a reverse proxy that uses paths instead of distinct domains. e.g. domain.com/ide/123456
. The service-worker script introduced in #154 will try to load the script from domain.com/service-worker.js
instead of domain.com/ide/123456/service-worker.js
.
~It should be sufficient~ (it’s not) to remove the leading slash in navigator.serviceWorker.register("/service-worker.js");
. So either navigator.serviceWorker.register("./service-worker.js");
or navigator.serviceWorker.register("service-worker.js");
. But I haven’t tested all scenarios, yet.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
service-worker script wont load from non-root path #670 - GitHub
The service-worker script introduced in #154 will try to load the script from domain.com/service-worker.js instead of domain.com/ide/123456/ ...
Read more >Service worker is not being used on non root path
It's registering, adding all the files I need to the cache, but it's not being used. My service worker is registering with scriptURL...
Read more >Using Service Workers - Web APIs | MDN
The path to your service worker file is not written correctly — it needs to be written relative to the origin, not your...
Read more >How to add service-worker.js file at the root directory with any ...
I want to add service-worker.js file at the root directory for the push notification. I found that root directory can not edit as...
Read more >A guide to Service Workers - pitfalls and best practices
One of the early mistakes that one might make, is to include the service worker script into some sub-directory without specifying a scope....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Actually, the register worked, it was the resulting CSP issues that popped up later. I got around some with making workbox local vs hosted on the CDN. I will PR that part while I work out a better solution on the CSP.
@geiseri what issues did you encountered while working on this? The simple
navigator.serviceWorker.register('service-worker.js', {scope: './'})
solution seems to work fine for me.Paths from the manifest and links to assets inside the
index.html
shouldnt be a problem:I would love to see a solution without another CLI-option. The IDE shouldn’t care about where it is mounted.