[Angular] Service Worker Version Management
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();
});
}
}
}
[Angular] Service Worker Version Management的更多相关文章
- Service Worker MDN英文笔记
前言: 以前学习基础知识的时候总看别人写的入门文章,但有时候还是一脸懵逼,直到自己用心阅读了MDN的英文文档才对基础知识的一些理论有了更深的理解,所以我在边阅读文档的时候边记录下帮助比较大的,也方便大 ...
- [PWA] 9. Service worker registerion && service work's props, methods and listeners
In some rare cases, you need to ask user to refresh the browsser to update the version. Maybe becaus ...
- [PWA] 2. Service worker life cycle
Once serive worker is registered, the first time we go to the app, we cannot see the logs from servc ...
- Service Worker 离线无法缓存Post请求的问题解决
许多非REST API甚至可以用于读取数据的POST请求:典型的例子是graphql.soap和其他rpcpapi.但是,Post请求不能在一个现成的渐进式Web应用程序中缓存和脱机使用.浏览器的缓存 ...
- [PWA] Show Notifications when a Service Worker is Installed or Updated
Service Workers get installed and activated in the background, but until we reload the page they don ...
- 浅析Service Worker
一.service worker是什么? 平常浏览器窗口中跑的页面运行的是主JavaScript线程,DOM和window全局变量都是可以访问的. Service Worker是走的另外的线程,可以理 ...
- service worker介绍
原文:Service workers explained 译者:neal1991 welcome to star my articles-translator, providing you advan ...
- Service Worker的应用
Service Worker的应用 Service worker本质上充当Web应用程序.浏览器与网络(可用时)之间的代理服务器,这个API旨在创建有效的离线体验,它会拦截网络请求并根据网络是否可用来 ...
- Service worker (@nuxtjs/workbox) 采坑记
PWA(Progressive Web App)是前端的大趋势,它能极大的加快前端页面的加载速度,得到近乎原生 app 的展示效果(其实难说).PWA 其实是多种前端技术的组合,其中最重要的一个技术就 ...
随机推荐
- mybits 操作指南
第一.一对一: <resultMap type="com.zktx.platform.entity.tb.Module" id="BaseResultMap&quo ...
- vim下很好的右键复制方法
1)先按shift ,然后鼠标选中即可复制:(shift按下时为非vim环境) 2)好方法: "Enable and disable mouse use noremap <f1> ...
- Mysql库的操作
一.系统数据库 执行如下命令,查看系统库 show databases; information_schema: 虚拟库,不占用磁盘空间,存储的是数据库启动后的一些参数,如用户表信息.列信息.权限信息 ...
- 带中横线的日期格式在iOS手机系统上 转换时间戳NaN问题
类似于 '2019-04-01 14:13:00' 这样的日期格式转换时间戳在iOS手机上是无法转换的,需要先处理日期格式成 '2019/04/01 14:13:00' var str = '2019 ...
- C# WinForm的练习
今天写了一个WinForm的练习,将源代码贴出来和大家一起学习学习. 首先:按照下图将一个button控件.三个RadioButton控件.三个CheckBox控件.一个Label控件和一个Track ...
- vue-cli3+typescript+router
vue基于类的写法,和基于对象的写法并不一致.使用vue-cli3创建的项目,src目录下的文件结构并没有多大区别,store.router.app.view.components.aeests该有的 ...
- Android 关于Toolbar和FragmentActivity的问题
今天在工作中遇到用Fragment搭Tab框架时,FragmentActivity无法使用Toolbar的问题.查了许多资料,其实AppComponent继承自FragmentActivity,所以A ...
- wpf 错误 执行了 QueryInterface 调用,请求提供 COM 可见的托管类“BoilerMonitoringV1._0.MapControl”的默认 IDispatch 接口。
在做wpf嵌入地图时,在自定义的WebBrowser 里面使用JavaScript调用外部方法的时报的错误 在原来的WinForm里 我们只要在窗体类设置的头部设置个 [System.Runtime. ...
- MongoDB_"Error parsing YAML config file: yaml-cpp: error at line 3, column 9: illegal map value"解决方法
在启动配置文件的时候,系统报错:Error parsing YAML config file: yaml-cpp: error at line 3, column 9: illegal map val ...
- eclipse创建maven的ssm项目
自己接触ssm框架有一段时间了,从最早的接触新版ITOO项目的(SSM/H+Dobbu zk),再到自己近期来学习到的<淘淘商城>一个ssm框架的电商项目.用过,但是还真的没有自己搭建过, ...