有新更新可用时,Angular 4 PWA Service Worker不会更新 [英] Angular 4 PWA Service Worker doesn't update when new updates available
问题描述
在我更新了Angular 4 PWA应用并部署后,用户直到清除缓存并刷新浏览器后才能获得新更新. Sw不会更新. 即使我按crome Dev中的更新按钮,它也不会更新,我必须清除缓存并刷新浏览器.
After i update my Angular 4 PWA app and deployed , user not getting new updates until user clear the cache and refresh the browser. Sw doesn't update. Even i press the update button in crome Dev it doesn't update I have to clear the cache and refresh the browser.
我用了这些包裹 @ angular/service-worker @ angular/platform-server ng-pwa-tools
I used these packages @angular/service-worker @angular/platform-server ng-pwa-tools
推荐答案
确保您的应用不时地检查服务器上的更新 .
Make sure your app checks for updates from the server from time to time.
在app.component.ts
中,将private swUpdate: SwUpdate
添加到构造函数中.
In the app.component.ts
add private swUpdate: SwUpdate
into the constructor.
this.swUpdate.available.subscribe(event => {
if (confirm('Update Available. Refresh the page now to update the cache.')) {
location.reload(true);
} else {
console.log('continue with the older version');
}
});
setInterval(() => {
this.swUpdate.checkForUpdate();
}, 21600);
这篇关于有新更新可用时,Angular 4 PWA Service Worker不会更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!