'Automagic reload for clients browser after deploy Angular 9
import { Component, OnInit } from '@angular/core';
import { SwUpdate } from '@angular/service-worker';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
constructor(private updates: SwUpdate){
this.updateClient();
}
ngOnInit() {
setInterval(() => {
this.updateClient();
}, 10000);
}
updateClient(){
if(!this.updates.isEnabled){
return;
}
this.updates.available.subscribe((event)=>{
console.log("current1",event.current,"available1",event.available);
if(confirm('Update available for the Application Please Confirm')){
this.updates.activateUpdate().then(()=>{location.reload()});
}
});
this.updates.activated.subscribe((event)=>{
console.log("current2",event.previous,"available2",event.current);
});
}
}
many time i'm facing one issue hot fix code not working in production, once the client hard refresh the browser the changes are comming, now i want to now in code level how to identify deployment, then forcefully hard fresh the client browser. im using service worker in above code app.component.ts every 1 minutes i have check update available, If any update available i will reload the application . but its not working. Is anybody have answer please share your comments...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
