[PWA] Deal with caches in PWA
in with pwa
2023-09-14 08:59:17 时间
The takeway is to know when we should cache the content? When we should clean the caches?
1. When should cache the content?
const CACHE_NAME = 'v1'; self.addEventListener('install', function (event) { // waitUntil take a promise event.waitUntil( caches.open(CACHE_NAME).then(function (cache) { return cache.addAll([ '/', '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' ]); }) ); });
This should be done in the 'install' event.
2. When should clean old cache?
self.addEventListener('activate', function (event) { // waitUntil take a promise event.waitUntil( // caches.keys, return all the cache names caches.keys().then(function (cacheNames) { return Promise.all( // only get cache for this application cacheNames.filter(function(name) { return name !== CACHE_NAME && name.startsWith('witter-'); }).map(function(cacheName) { // delete each cache by name return caches.delete(cacheName); }) ); }) ); });
This should be done in 'activate' event, the new cache should be already cached if the SW version doesn't change. If it does change, then the new version will be stored and we need to clean the old one, the best place to do it is in the 'activate' event.
相关文章
- BUG记录:Error creating bean with name ‘xxx’ defined in file
- 快速搭建Fabric测试网络(Docker in Ubantu 18.04 TLS)
- ORA-00341: log string of thread string, wrong log # string in header ORACLE 报错 故障修复 远程处理
- ORA-24388: Unsupported functionality in fast path mode ORACLE 报错 故障修复 远程处理
- ORA-29875: failed in the execution of the ODCIINDEXINSERT routine ORACLE 报错 故障修复 远程处理
- ORA-32038: number of WITH clause column names does not match number of elements in select list ORACLE 报错 故障修复 远程处理
- ORA-41703: invalid child node in “object” element with “ref” attribute ORACLE 报错 故障修复 远程处理
- ORA-42303: duplicate column reference in a definition of an Editioning view ORACLE 报错 故障修复 远程处理
- ORA-06596: object cannot be purged, object is permanently kept in shared pool ORACLE 报错 故障修复 远程处理
- ORA-14153: only one of STORE IN or clause may be specified ORACLE 报错 故障修复 远程处理
- 利用Oracle中IN函数进行数据查询(oracle带in函数)
- 查询利用Oracle In查询实现列值范围筛选(oracle列值in)
- MySQL中IN查询的使用及效率优化(mysql中in的0)
- MySQL中使用IN子句出现重复值问题的解决方法(mysql中in有重复值)
- MySQL不支持IN运算符如何解决(mysql 不支持in)
- 条件在Oracle中使用IN和OR查询条件的巧妙之处(oracle中in跟or)
- 使用Oracle中的IN方法精准查找数据(oracle中in方法)
- 深究Oracle中的IN子查询(oracle中in子查询)
- 语句使用Oracle两个WITH语句实现数据查询(oracle两个with)
- 企业办公租赁免押金的第一步,芝麻信用“All in 消灭押金”的一大步