sha*_*nka 6 javascript service-worker angular
在我更新我的 Angular 4 PWA 应用程序并部署之后,在用户清除缓存并刷新浏览器之前,用户不会获得新的更新。Sw 不更新。即使我按下 crome Dev 中的更新按钮,它也不会更新我必须清除缓存并刷新浏览器。
我使用了这些包@angular/service-worker @angular/platform-server ng-pwa-tools
确保您的应用不时检查来自服务器的更新。
在app.component.ts添加private swUpdate: SwUpdate到构造函数中。
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);
Run Code Online (Sandbox Code Playgroud)
根据您提供的信息,我猜您的网络服务器正在为 SW 文件提供一些缓存标头,并且访问者的浏览器使用缓存版本。
请务必将缓存标头显式设置为 no-cache/-1/etc。以便浏览器始终检查 Web 服务器是否有新版本的 service-worker.js(或其他)文件。
| 归档时间: |
|
| 查看次数: |
3346 次 |
| 最近记录: |