service-worker-communications: lazy-loading and promptUser
See original GitHub issueπ Docs or angular.io bug report
Description
@Injectable()
export class PromptUpdateService {
constructor(updates: SwUpdate) {
updates.available.subscribe(event => {
if (promptUser(event)) {
updates.activateUpdate().then(() => document.location.reload());
}
});
}
}
Doing this could break lazy-loading in currently running apps, especially if the lazy-loaded chunks use filenames with hashes, which change every version.
-
The documentation seems incomplete. What should we do if we are using lazy-loading but we want our users to update to the latest version of the app?
-
I think it would be helpful to explain what
promptUser
is too. If itβs function the developer is expected to write himselfβwhich seems to be the caseβthen that could be made more clear like this:
@Injectable()
export class PromptUpdateService {
constructor(updates: SwUpdate) {
updates.available.subscribe(event => {
if (this.promptUser(event)) {
updates.activateUpdate().then(() => document.location.reload());
}
});
}
private promptUser(event: UpdateAvailableEvent): boolean {
// prompt the user if now would be a good time to reload the app
}
}
π¬ Minimal Reproduction
Whatβs the affected URL?**
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Service worker communication - Angular
The SwUpdate service gives you access to events that indicate when the service worker discovers and installs an available update for your application....
Read more >Lazy loading - Web performance | MDN
Lazy loading is a strategy to identify resources as non-blocking (non-critical) and load these only when needed. It's a way to shorten theΒ ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thx for the info, @kapunahelewong. This looks like an oversight, so look letβs move forward with #37555.
Interestingly, there was a comment about clarifying that bit in the original PR, but it was apparently never addressed: https://github.com/angular/angular/pull/20021#discussion_r149189505
P3 to at least reassess where this is after 2 years of nothing happening with it.