[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 其实是多种前端技术的组合,其中最重要的一个技术就 ...
随机推荐
- 高效管理 Elasticsearch 中基于时间的索引——本质是在利用滚动模式做数据的冷热分离,热索引可以用ssd
高效管理 Elasticsearch 中基于时间的索引 转自:http://stormluke.me/es-managing-time-based-indices-efficiently/ 用 Ela ...
- hdoj--1151--Air Raid(最大独立集)
Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- 29. Divide Two Integers[M]两数相除
题目 Given two integers dividend and divisor, divide two integers without using multiplication, divisi ...
- POJ 3620 DFS
题意: 给你n*m的矩形,有k个坏点 问最大坏点连通块的坏点数. 一发水题.. 裸的DFS // by SiriusRen #include <cstdio> #include <a ...
- python简易版学生管理系统
#coding=utf- def showInfo(): print("**************") print(" 学生管理系统") print(&quo ...
- 修改Myeclipse中项目在tomcat上发布的名称
1.从网上找的,但是没有用 2.直接修改工作空间中的文件
- Selenium的文件上传JAVA脚本
在写文件上传脚本的时候,遇到了很多问题,包括元素定位,以及上传操作,现在总结下来以下几点: 1. 上传的控件定位要准确,必要时要进行等待 WebElement adFileUpload = drive ...
- NPOI导出功能
利用NPOI组件将数据中想要的数据导出到excel表格中. demo如下 using System; using System.Collections.Generic; using System.Li ...
- 本地sql文件导入mysql数据库
mysql中配置my.ini interactive_timeout = 120 wait_timeout = 120 max_allowed_packet = 32M 导入sql运行命令 sourc ...
- Windows系统开发常用类-------------Environment类
Windows系统开发常用类-------------Environment类: SystemDirectory//显示系统目录 MachineName//计算机名称 ...