Has anyone got any experience of js service workers?

Hey Makers

I was using service workers on my site and recently notice an error which creates multiple service workers in some pages if no cache is present, any one has used them earlier?

I've used it with create react app, found them unreliable when pages updated.

0 Likes

I have also found that they're not great if you want users to instantly be up to date when they load a page, however I don't always need that so I still use them (offline support, baby!).

0 Likes
Ankit Ghosh Author

The features are working like caching and offline page.. But issue is when a use directly lands on a particular page say abc.xyz/demo/index.html then scope of sw becomes abc.xyz/demo wher scope should be /, got any ideas on this?

0 Likes

You could add / in front of everything, that works for me.

0 Likes

Also: no markdown here! Noted!

0 Likes
Ankit Ghosh Author

No the issue is if visitor goes directly to abc.com/demo/anything.html the sw gets registered for abc.com/demo and if the visitor then visits abc.com then again a new sw is registered with socpe abc.com

Still unable to find the issue also i have mentioned the scope to be / in js but seems to have some error which isn't seen

0 Likes

You should have only one SW file (service-worker.js, sw.js, whatever) in the root and link to that, then, in the cache list have / in front of everything

0 Likes
Ankit Ghosh Author

Yes. I use only one example.com/service-worker.js

0 Likes

And do you have / in front of every file in your list?

0 Likes
Ankit Ghosh Author

Yes I know this issue so for precaution I generally use the whole url with https

0 Likes

Please sign in to leave a comment.