So once you modify the code, service worker will auto create a new one and it won't take control over until the previous service work total die(close the tab or nav to a new url). The new service work is in the waiting list.

Now what we want to do is delete the old caches and only keep the one which is latest installed.

So the way to do this, is in 'activate' state. So once anything changed, a new service worker is created and push into the waiting list. Then we want to delete old caches only keep the static one.

var staticCacheName = 'wittr-demo-v13';

self.addEventListener('install', function(event) {
var urlsToCache = [
'/',
'js/main.js',
'css/main.css',
'imgs/icon.png',
'https://fonts.gstatic.com/s/roboto/v15/2UX7WLTfW3W8TclTUvlFyQ.woff',
'https://fonts.gstatic.com/s/roboto/v15/d-6IYplOFocCacKzxwXSOD8E0i7KZn-EPnyo3HZu7kw.woff'
]; event.waitUntil(
caches.open(staticCacheName).then( (cache) => {
cache.addAll(urlsToCache);
})
);
}); self.addEventListener('activate', function(event){
event.waitUntil(
// Get all the cache name
caches.keys().then(function(cacheNames){
// wait all cache deleted
return Promise.all(
// filter out staticCacheName (only keep staticCacheName)
cacheNames.filter( function(name){
return name.startsWith('wittr') && name != staticCacheName;
}).map(function(name){
// delete cache, return promise
return caches.delete(name);
})
)
})
)
})

So in the code, the static one is 'wittr-demo-v13'.

We use two apis:

caches.keys() // return a promise with all the cache name

caches.delete(name) // return a promise and delete the selected cache

Now only v13 is left.

[PWA] 8.Unobtrusive update: Delete old cache and only keep one, hard refresh to let new SW to take control的更多相关文章

  1. 关于MyBatis mapper的insert, update, delete返回值

    这里做了比较清晰的解释: http://mybatis.github.io/mybatis-3/java-api.html SqlSession As mentioned above, the Sql ...

  2. PHP5: mysqli 插入, 查询, 更新和删除 Insert Update Delete Using mysqli (CRUD)

    原文: PHP5: mysqli 插入, 查询, 更新和删除  Insert Update Delete Using mysqli (CRUD) PHP 5 及以上版本建议使用以下方式连接 MySQL ...

  3. 如何判断一条sql(update,delete)语句是否执行成功

    如何判断一条sql(update,delete)语句是否执行成功 catch  (SQLException    e)  {  }  catch不到错误应该就成功了.   ============== ...

  4. ECSHOP后台SQL查询提示错误 this sql May contain UPDATE,DELETE,TRUNCATE,ALTER,DROP,FLUSH,INSERT

    一).首先说一下错误现象:市面上流行的绝大部分ECSHOP模板,安装的时候都需要执行一段或几段SQL语句来修改数据结构或者初始化一些数据.大多数ECSHOP管理员为了省事,都会通过 “ECSHOP后台 ...

  5. mysql 防止update/delete误操作

    身为一php开发攻城狮,常常涉及在应用中写update/delete语句,忘记加where,后果不堪设想. 还会出现在cml下直接操作mysql的情况,如果mysql 权限够大,一个update/de ...

  6. mysql 事务是专门用来管理insert,update,delete语句的,和select语句一点不相干

    1.mysql 事务是专门用来管理insert,update,delete语句的,和select语句一点不相干 2.一般来说,事务是必须满足4个条件(ACID): Atomicity(原子性).Con ...

  7. [Hive - LanguageManual] DML: Load, Insert, Update, Delete

    LanguageManual DML Hive Data Manipulation Language Hive Data Manipulation Language Loading files int ...

  8. AngularJS Tabular Data with Edit/Update/Delete

    效果 首先,我们先建立一些数据,当然你可以从你任何地方读出你的数据 var app = angular.module('plunker', ['ui.bootstrap']); app.control ...

  9. MySQL 误删数据、误更新数据(update,delete忘加where条件)

    MySQL 误操作后数据恢复(update,delete忘加where条件) 关键词:mysql误删数据,mysql误更新数据 转自:https://www.cnblogs.com/gomysql/p ...

随机推荐

  1. TaskbarCreated 消息

    托盘中的图片就通过注册这个消息来实现,系统和进程通过进程间通信发送这个消息,进程接收他

  2. Chrome调试(转)

    原文地址:http://blog.csdn.net/chenmoquan/article/details/44943245#comments 觉得写的很适合web开发的新手 Chrome 的开发者工具 ...

  3. 《gzip命令》-linux命令五分钟系列之七

    本原创文章属于<Linux大棚>博客. 博客地址为http://roclinux.cn. 文章作者为roc 希望您能通过捐款的方式支持Linux大棚博客的运行和发展.请见“关于捐款” == ...

  4. Ubuntu 12.04 下安装配置 JDK 7(tar)

    第一步:下载jdk-7u45-linux-i586.tar.gz 到Orcale的JDK官网下载JDK7的tar包 第二步:解压安装 tar -zxvf ./jdk-7u45-linux-i586.t ...

  5. seajs打包部署工具spm的使用总结

    相信使用seajs的好处大家都是知道的,接触seajs好像是在半年前,当时还不知道页面阻塞问题,这里不带多余的话了. seajs实现了模块化的开发,一个网站如果分了很多很多模块的话,等开发完成了,发现 ...

  6. Struts2 cookie的存取

    /** * Cookieの追加 * @return * @throws Exception */ private void addCookie(String name,String value){ C ...

  7. 【HDOJ】2319 Card Trick

    水题,STL双端队列. /* 2319 */ #include <iostream> #include <cstdio> #include <cstring> #i ...

  8. 组合数学(Pólya计数原理):UvaOJ 10601 Cubes

    Cubes You are given 12 rods of equal length. Each of them is colored in certain color. Your task is ...

  9. 【扩展欧几里得】BAPC2014 I Interesting Integers (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  10. oracle 表查询(1)

    oracle 表基本查询 介绍在我们讲解的过程中我们利用scott 用户存在的几张表(emp,dept)为大家演示如何使用select语句,select 语句在软件编程中非常有用,希望大家好好的掌握. ...