Hello everybody, first post here I hope I’m doing it correctly!
I have an Angular application which is using service worker to update itself live.
Meaning that the user, as soon as the service worker detects an update, will have the website reloaded. That is working correctly when hosted on digital ocean spaces while hosting on Netlify will result in the service worker never detecting a new update.
constructor(public updates: SwUpdate){
if (updates.isEnabled) {
updates.available.subscribe(event => {
this.alertService.updateAlert('Application', 'A new version is available, to keep navigating the website will be reloaded.').then(
res => {
updates.activateUpdate().then(() => document.location.reload());
}
)
});
} else {
console.log("SERVICE WORKER NOT ENABLED")
}
}
This is an example code of what I’m doing.
I can see the service worker registered on the browser.
If I reload the website everything is updated as expected without the warning to the user.
I’ve crossposted somedays ago on those other websites:
reddit
stackoverflow
I hope it is not against the rules.
Update 1: I found a possible solution I’m trying to build with the assets optimization disabled to see if it works.
Update 2: Minutes have passed and the service worker is not asking to update
I’m also trying to force him to look for updates but still nothing.
interval(60 * 1000).subscribe(() => {
console.log('checking for updates')
updates.checkForUpdate()
});