New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service worker cache localisation #1453
Comments
Maybe some of the ideas outlined by @jeffposnick in this StackOverflow answer are applicable? |
It's also worth reading https://web.dev/google-search-sw/#problem:-experiments-and-dynamism, which describes the approach the Google Search team took when implementing a service worker: they took advantage of the control offered by dynamically generating a service worker script server-side, based on the incoming HTTP request. There's an extra burden of maintaining the server-side code, and it's a different approach when you start thinking about using the service worker API "dynamically," but it does give you the most flexibility. |
I will check out this article. I was wondering if I was over complicating things by thinking about a dynamic service worker but it would give me the flexibility I need to handle some of our requirements. @tomayac @jeffposnick thanks for getting back to me. I will populate this issue with my findings incase anyone is interested in what we did. |
@jakearchibald if you are interested here is how we went around solving our issues: https://medium.com/@robinglen/how-we-built-a-service-worker-for-our-micro-frontends-881eabfbf267 |
Sorry this is not really an issue but a question / problem I was having and wasn't sure where to ask.
I'm trying to implement a service worker that will sit at the root of our website however it will need to cache assets that it is unaware of. They are coming from a collection of domain specific microservices and I don't want teams to need to release SW as part of their deployment pipeline.
Todo this when each service is built it creates it's own asset manifest similar to this:
There is then a service that collects all our services assets manifests and generates a sw cache manifest:
This is uploaded along with our assets to a bucket that is internet facing. Then our service worker loads in this json file at boot time and passes a merged array of assets to
workbox.precaching.precacheAndRoute
.This means that our service worker doesn't need to have an understanding of what our separate teams are releasing, or even if we add a new service, the cache can always be up to date. However my issue does in because we also support multiple languages.
This means I want to load different assets into the cache based on the users set language, I looked at a few different options:
So my final thought was to register a service worker dynamically based out the url:
From here then the service worker could call the sw cache manifest which could return something like:
Then it would know as the
en-sw
to use theen
array.However this would involve either generating multiple service workers (one per language) or service workers are actually generated programmatically based on the in bound request.
At this point I'm not entirely sure if I'm over thinking this and there is a much simpler way of doing it... so just wondering if this is a problem anyone else has had and how they solved it.
Thanks,
Robin
The text was updated successfully, but these errors were encountered: