From acd286e8ee9f6a33c2a52a78da80f023f7316dd2 Mon Sep 17 00:00:00 2001 From: shixuewen Date: Mon, 12 Feb 2024 23:14:09 +0800 Subject: [PATCH 1/2] fix: pwa clear cache --- apps/u3/src/service-worker.ts | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/apps/u3/src/service-worker.ts b/apps/u3/src/service-worker.ts index 60589072..cbe0d8f1 100644 --- a/apps/u3/src/service-worker.ts +++ b/apps/u3/src/service-worker.ts @@ -92,14 +92,21 @@ self.addEventListener('push', (event) => { }); }); -// const CALL_BACK_INTERVAL = 1000 * 60 * 60; -// self.addEventListener('activate', () => { -// console.log('activate interval subscribe......'); -// setInterval(() => { -// console.log('fire notification!'); -// self.registration.showNotification('U3', { -// body: 'Checkout new content on Farcaster', -// icon: `${process.env.PUBLIC_URL}/logo192.png`, -// }); -// }, CALL_BACK_INTERVAL); -// }); +self.addEventListener('activate', function (event) { + // 清除旧缓存 + event.waitUntil( + caches.keys().then(function (cacheNames) { + return Promise.all( + cacheNames + .filter(function (cacheName) { + // 过滤出旧的缓存 + return cacheName !== 'my-cache'; + }) + .map(function (cacheName) { + // 删除旧的缓存 + return caches.delete(cacheName); + }) + ); + }) + ); +}); From a6a6df5b6e38d1c3529dba617547828dddef439d Mon Sep 17 00:00:00 2001 From: shixuewen Date: Mon, 12 Feb 2024 23:20:21 +0800 Subject: [PATCH 2/2] fix: pwa cache check main.js --- apps/u3/src/service-worker.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/u3/src/service-worker.ts b/apps/u3/src/service-worker.ts index cbe0d8f1..c36c940d 100644 --- a/apps/u3/src/service-worker.ts +++ b/apps/u3/src/service-worker.ts @@ -100,7 +100,8 @@ self.addEventListener('activate', function (event) { cacheNames .filter(function (cacheName) { // 过滤出旧的缓存 - return cacheName !== 'my-cache'; + return cacheName.startsWith('main.'); + // return cacheName !== 'my-cache'; }) .map(function (cacheName) { // 删除旧的缓存