Skip to content

Commit

Permalink
fix: 🐛 新版本直接清理缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
adams549659584 committed May 8, 2023
1 parent 87ba94b commit 521b65b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 19 deletions.
39 changes: 22 additions & 17 deletions web/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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();
};
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.4.0';
const SW_VERSION = 'v1.4.1';
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.17',
revision: '2023.05.08',
},
// html
{
Expand Down

0 comments on commit 521b65b

Please sign in to comment.