Service Worker: allow service worker to checkForUpdate and activateUpdate before bootstraping the AppModule
See original GitHub issue🚀 feature request
Provide a way to check for updates and activate them before the main AppModule is bootstrapped.
Relevant Package
This feature request is for @angular/service-worker
Description
Currently, if we use the service worker module(which we want to use in order to support offline mode) we have no choice but always serve a cached(potentially outdated) version when a user opens our app. And only then we can check for updates in the background.
What we want is to check for updates before bootstrapping the app and if there are any then first activate them and only after that bootstrap an app. We want to be sure that a user starts her working day with a fresh version of our app (if for example there was an overnight update).
We considered force page reload and showing a prompt for a user to activate a new version but that would not be the best UX choice in our scenarios(we do updates a couple of times daily).
Describe the solution you’d like
Provide an API to access service worker’s checkForUpdate
, available
and activateUpdate
properties outside of a module/service so it can be done in main.ts
.
Describe alternatives you’ve considered
We can’t remove the service worker since we want offline support. We can’t force refresh as it’s a bad UX for us(we can on navigation between routes but that would be too late) We can’t show prompt as it will appear almost every morning for the user.
We consider showing a spinner in app.component until we make all checks through the ServiceWorkerModule as an alternative but that would be a waste of the device’s(in case of mobile) resources to parse and execute all JS to then find out it’s not needed.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top GitHub Comments
You are welcome. I’ll go ahead and close this issue, since it is not actionable as is (i.e. we will not expose
SwUpdate
outside of the Angular app - and even that wouldn’t be a great solution anyway).I’ll let you play with the data-group work-around and eventually #38565 (in v11). Feel free to open a new issue to suggest further changes/enhancements to the SW configuration capabilities (e.g. specifying a timeout for navigation requests with the
freshness
strategy). (Also, feel free to continue the discussion below, if needed.)This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.