Comments (14)
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?
from servor.
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
from servor.
Humm, that seems a little more involved.. would putting it on every request break the site or service worker?
from servor.
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.
from servor.
Ok, do you think a service worker file naming convention (like *.sw.js
) could work?
from servor.
I think it will. But how do you customize the value of that header per service worker served?
from servor.
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?
from servor.
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
from servor.
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?
from servor.
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)
from servor.
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
from servor.
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 ;)
from servor.
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.
from servor.
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!
from servor.
Related Issues (20)
- Doesn't detect change in nested files (on Linux) HOT 23
- Proxy support HOT 10
- setuid breaks local secure serving on linux HOT 5
- --reload causes browsers to enter quirks mode HOT 3
- Option for disable the injection of base tag HOT 4
- Media streaming issues with Chrome HOT 6
- Starting two instances of Servor without port cause them having the same port HOT 2
- `sudo servor --secure` throws `EACCES: permission denied` HOT 3
- Add flow support HOT 2
- Wait for write to finish HOT 3
- Support https for LAN IP HOT 1
- Trailing slash on SPA route HOT 2
- servor crashes on st terminal in Ubuntu HOT 5
- Please support etag and last-modified
- Vertical scroll position resets when servor triggers reloading in Firefox
- [Feature Request] Inject livereload to each html file
- [Feature Request] Allow multiple roots
- Listen on localhost only HOT 1
- crt and key file location for secure start HOT 2
- Support already encoded files (gz, br) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from servor.