fix: Clear 2.1.0 frontend PWA cache (#6933)

Co-authored-by: Louis Lam <louislam@users.noreply.github.com>
This commit is contained in:
Copilot
2026-02-18 13:16:49 +08:00
committed by GitHub
parent 6a9f800f58
commit 239ff865bf
2 changed files with 20 additions and 1 deletions

View File

@@ -1,3 +1,20 @@
self.addEventListener("install", function (event) {
self.skipWaiting();
});
// Clear old caches from vite-plugin-pwa
self.addEventListener("activate", function (event) {
event.waitUntil(
(async function () {
const cacheNames = await caches.keys();
for (const cacheName of cacheNames) {
await caches.delete(cacheName);
}
await self.clients.claim();
})()
);
});
// Receive push notifications
self.addEventListener("push", function (event) {
if (self.Notification?.permission !== "granted") {

View File

@@ -44,8 +44,10 @@ app.component("FontAwesomeIcon", FontAwesomeIcon);
app.mount("#app");
// Service Worker
// Mainly for Webpush notification
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("/sw.js", { scope: "/" }).catch((error) => {
navigator.serviceWorker.register("/serviceWorker.js", { scope: "/" }).catch((error) => {
console.error("Service worker registration failed:", error);
});
}