Coder Social home page Coder Social logo

Service Workers about servor HOT 14 CLOSED

lukejacksonn avatar lukejacksonn commented on May 15, 2024
Service Workers

from servor.

Comments (14)

lukejacksonn avatar lukejacksonn commented on May 15, 2024

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.

flasaracina avatar flasaracina commented on May 15, 2024

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.

lukejacksonn avatar lukejacksonn commented on May 15, 2024

Humm, that seems a little more involved.. would putting it on every request break the site or service worker?

from servor.

flasaracina avatar flasaracina commented on May 15, 2024

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.

lukejacksonn avatar lukejacksonn commented on May 15, 2024

Ok, do you think a service worker file naming convention (like *.sw.js) could work?

from servor.

flasaracina avatar flasaracina commented on May 15, 2024

I think it will. But how do you customize the value of that header per service worker served?

from servor.

lukejacksonn avatar lukejacksonn commented on May 15, 2024

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.

flasaracina avatar flasaracina commented on May 15, 2024

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.

lukejacksonn avatar lukejacksonn commented on May 15, 2024

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.

flasaracina avatar flasaracina commented on May 15, 2024

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.

lukejacksonn avatar lukejacksonn commented on May 15, 2024

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.

flasaracina avatar flasaracina commented on May 15, 2024

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.

lukejacksonn avatar lukejacksonn commented on May 15, 2024

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.

lukejacksonn avatar lukejacksonn commented on May 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.