From 521b65be0c32c788c221e447085654fa30da9020 Mon Sep 17 00:00:00 2001 From: adams549659584 <13760614423@163.com> Date: Mon, 8 May 2023 13:00:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20:bug:=20=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E6=B8=85=E7=90=86=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/js/index.js | 39 ++++++++++++++++++++++----------------- web/sw.js | 4 ++-- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/web/js/index.js b/web/js/index.js index e8fb47c5f7..7aae7da4c3 100644 --- a/web/js/index.js +++ b/web/js/index.js @@ -107,8 +107,9 @@ async function registerSW() { console.log('Service Worker 安装成功:', event); const newSWVersion = await wb.messageSW({ type: 'GET_VERSION' }); if (newSWVersion !== oldSWVersion) { + await clearCache(); alert(`新版本 ${newSWVersion} 已就绪,刷新后即可体验 !`); - window.location.reload(true); + window.location.reload(); } }); @@ -163,6 +164,25 @@ function hideLoading() { loadingEle.classList.add('hidden'); } +async function clearCache() { + // del storage + localStorage.clear(); + sessionStorage.clear(); + // del sw + const cacheKeys = await caches.keys(); + for (const cacheKey of cacheKeys) { + await caches.open(cacheKey).then(async (cache) => { + const requests = await cache.keys(); + return await Promise.all( + requests.map((request) => { + console.log(`del cache : `, request.url); + return cache.delete(request); + }) + ); + }); + } +} + (function () { var config = { cookLoc: {} }; sj_evt.bind( @@ -217,22 +237,7 @@ function hideLoading() { // del cookie setCookie(userCookieName, '', -1); setCookie(randIpCookieName, '', -1); - // del storage - localStorage.clear(); - sessionStorage.clear(); - // del sw - const cacheKeys = await caches.keys(); - for (const cacheKey of cacheKeys) { - await caches.open(cacheKey).then(async (cache) => { - const requests = await cache.keys(); - return await Promise.all( - requests.map((request) => { - console.log(`del cache : `, request.url); - return cache.delete(request); - }) - ); - }); - } + await clearCache(); chatLoginBgEle.style.display = 'none'; window.location.reload(); }; diff --git a/web/sw.js b/web/sw.js index 4be41b96c7..847724dfbe 100644 --- a/web/sw.js +++ b/web/sw.js @@ -1,7 +1,7 @@ // 引入workbox 框架 importScripts('./js/sw/workbox-sw.js'); -const SW_VERSION = 'v1.4.0'; +const SW_VERSION = 'v1.4.1'; const CACHE_PREFIX = 'BingAI'; workbox.setConfig({ debug: false, logLevel: 'warn' }); @@ -56,7 +56,7 @@ workbox.precaching.precacheAndRoute([ }, { url: '/web/js/index.js', - revision: '2023.05.06.17', + revision: '2023.05.08', }, // html {