有新更新可用时,Angular 4 PWA Service Worker不会更新 [英] Angular 4 PWA Service Worker doesn't update when new updates available

查看:165
本文介绍了有新更新可用时,Angular 4 PWA Service Worker不会更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我更新了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆