Skip to content

Commit

Permalink
fix: 🐛 新版本才提示
Browse files Browse the repository at this point in the history
  • Loading branch information
adams549659584 committed May 6, 2023
1 parent 3209e26 commit 71f161b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions web/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions web/sw.js
Original file line number Diff line number Diff line change
@@ -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' });
Expand Down Expand Up @@ -56,7 +56,7 @@ workbox.precaching.precacheAndRoute([
},
{
url: '/web/js/index.js',
revision: '2023.05.06.14',
revision: '2023.05.06.15',
},
// html
{
Expand Down

1 comment on commit 71f161b

@vercel
Copy link

@vercel vercel bot commented on 71f161b May 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.