If our PWA application has a new version including some fixes and new features. By default, when you refresh your page, service worker will check ngsw.json file in dist folder to see whether any files updated, if yes, then service worker will download new assets.

Then in the second reload, new version will be installed.

But if we want to tell users there is a new version in the first page load, we can do:

import {Component, OnInit} from '@angular/core';
import {SwUpdate} from '@angular/service-worker';
import {MatSnackBar, MatSnackBarRef, SimpleSnackBar} from '@angular/material'; @Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit{ snackBarRef: MatSnackBarRef<SimpleSnackBar>;
constructor( private swUpdate: SwUpdate,
public snackBar: MatSnackBar) { } ngOnInit() {
// check that whether service worker is enabled or not
if (this.swUpdate.isEnabled) {
// if there is a new service worker version
this.swUpdate.available.subscribe(() => {
this.snackBarRef = this.snackBar.open('The new page is ready to update', 'Reload Page', {
duration: ,
});
}); // refresh the page
this.snackBarRef.onAction().subscribe(() => {
window.location.reload();
});
}
} }

最新文章

  1. JSP利用Hibernate实现对数据库的CRUD ——开发环境Myeclipse与SQL Server 2008
  2. 相同根域名下跨域共享session的解决方案
  3. java调用url接口
  4. C#中清空ListView中的数据
  5. 【BZOJ-3648】寝室管理 环套树 + 树状数组 + 点分治
  6. Git服务器、http协议及XCode
  7. 样式中的url加载探疑
  8. jstl fn标签
  9. C++视频课程小结(1)
  10. [Data Structure] 二叉搜索树(Binary Search Tree) - 笔记
  11. 使用Mina框架开发 QQ Android 客户端
  12. 一起来学canvas (前言)
  13. 比Spring简单的IoC容器
  14. 【Zookeeper】源码分析之Watcher机制(三)之Zookeeper
  15. Docker(五):Docker高级网络配置
  16. HDU 2717(* bfs)
  17. 微信小程序-遍历列表
  18. easyradius通讯接口 V4全新升级,显示同步失败原因,方便用户寻找故障
  19. CodeForces - 780C Andryusha and Colored Balloons(dfs染色)
  20. C#代码优化—字符串拼接效率比较

热门文章

  1. 局部变量,全局变量,extend,static
  2. bzoj2958: 序列染色(DP)
  3. Node.js:RESTful API
  4. LeetCode Weekly Contest 20
  5. nginx 集群简述
  6. PostgreSQL的HA解决方案-项目概述
  7. LoadRunner时间戳函数web_save_timestamp_param
  8. VFS文件系统结构分析 与socket
  9. 关于ZBrush中Subtool的小秘密
  10. day06-08面向对象的三大特性