From 71f161b58079e23cd906092239e6e010c925a853 Mon Sep 17 00:00:00 2001 From: adams549659584 <13760614423@163.com> Date: Sat, 6 May 2023 15:17:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20:bug:=20=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=89=8D=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/js/index.js | 13 ++++++++----- web/sw.js | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/web/js/index.js b/web/js/index.js index d8ff85667d..0bd3210b0a 100644 --- a/web/js/index.js +++ b/web/js/index.js @@ -102,11 +102,14 @@ async function registerSW() { if ('serviceWorker' in navigator && workbox) { window.addEventListener('load', async function () { const wb = new workbox.Workbox('sw.js'); + let oldSWVersion; wb.addEventListener('installed', async function (event) { console.log('Service Worker 安装成功:', event); - const swVersion = await wb.messageSW({ type: 'GET_VERSION' }); - alert(`新版本 ${swVersion} 已就绪,刷新后即可体验 !`); - window.location.reload(); + const newSWVersion = await wb.messageSW({ type: 'GET_VERSION' }); + if (newSWVersion !== oldSWVersion) { + alert(`新版本 ${swVersion} 已就绪,刷新后即可体验 !`); + window.location.reload(); + } }); wb.addEventListener('activated', function (event) { @@ -117,8 +120,8 @@ async function registerSW() { console.log('Service Worker 更新成功:', event); }); const swRegistration = await wb.register(); - const swVersion = await wb.messageSW({ type: 'GET_VERSION' }); - console.log('Service Worker Version:', swVersion); + oldSWVersion = await wb.messageSW({ type: 'GET_VERSION' }); + console.log('Service Worker Version:', oldSWVersion); }); } } diff --git a/web/sw.js b/web/sw.js index b7b3a66502..91356b77e7 100644 --- a/web/sw.js +++ b/web/sw.js @@ -1,7 +1,7 @@ // 引入workbox 框架 importScripts('./js/sw/workbox-sw.js'); -const SW_VERSION = 'v1.3.2'; +const SW_VERSION = 'v1.3.3'; 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.14', + revision: '2023.05.06.15', }, // html {