updated pwa sw
This commit is contained in:
+28
-6
@@ -3,18 +3,41 @@ import { precacheAndRoute } from "workbox-precaching";
|
||||
// Precaching configuration for PWA assets
|
||||
precacheAndRoute(self.__WB_MANIFEST);
|
||||
|
||||
const VERSION = "1.0.0";
|
||||
// Version
|
||||
|
||||
const VERSION = "1.0.423";
|
||||
|
||||
// Service Worker Installation
|
||||
self.addEventListener("install", (event) => {
|
||||
self.skipWaiting(); // Force activate new SW immediately
|
||||
console.log("Service Worker installed");
|
||||
self.skipWaiting();
|
||||
// Clear old cache during install
|
||||
event.waitUntil(
|
||||
caches.keys().then((cacheNames) => {
|
||||
return Promise.all(
|
||||
cacheNames.map((cache) => {
|
||||
if (cache !== self.registration.scope + "::" + VERSION) {
|
||||
return caches.delete(cache);
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// Service Worker Activation
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(self.clients.claim());
|
||||
console.log("Service Worker activated");
|
||||
event.waitUntil(
|
||||
(async () => {
|
||||
const clients = await self.clients.matchAll({ type: "window" });
|
||||
clients.forEach((client) => {
|
||||
client.postMessage({
|
||||
type: "VERSION_CHECK",
|
||||
version: VERSION,
|
||||
});
|
||||
});
|
||||
self.clients.claim();
|
||||
})()
|
||||
);
|
||||
});
|
||||
|
||||
// Push Notification Handler for Django Web Push
|
||||
@@ -48,6 +71,5 @@ self.addEventListener("notificationclick", (event) => {
|
||||
self.addEventListener("message", (event) => {
|
||||
if (event.data === "SKIP_WAITING") {
|
||||
self.skipWaiting();
|
||||
self.clients.claim();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user