I have an Angular 8 PWA app in production. I make a lot of updates regularly, so I need to find a way for users to get those updates when they open the app.
Without special action, the app won't update. If you open the app on your browser, it will show the version from when you last opened the app, even if I have pushed a new bundle to production. It seems this is an unfortunate result of PWA-functionality.
I am hosting with AWS Amplify.
To solve this (I had asked a question about it here), I have tried using swUpdate.
The problem is it works way too slow. It will reload the browser if there is an update--but it takes a while to do that. It regularly takes several seconds after a user opens the app for the reload to happen. So you open the app, and 4 to 6 seconds later the app reloads with the new version.
Is there a way to make swUpdate go faster? Or an alternative way to load the new app version?
Here's my code, which I think is a straightforward implementation:
app.component.ts:
import { Component } from '@angular/core';
import { SwUpdate } from '@angular/service-worker';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor(private swUpdate: SwUpdate) {
title = 'Great App'
swUpdate.available.subscribe(event => {
swUpdate.activateUpdate().then(() => {
window.location.reload();
console.log('there is an Update! Reloading now.')
});
})
if (!this.swUpdate.isEnabled) {
console.log('Not going to update');
}
}
But this is not working well, because the reload often happens several seconds after the user goes to the app (even on good internet connection).
I know that I could also show a message to people saying "Want to refresh with a new version?" But this would not address the underlying problem of how slow swUpdate currently works.