mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-07-30 20:38:22 +00:00
update roxmenux-monitor-v2
This commit is contained in:
@@ -8,12 +8,14 @@
|
||||
// so we do NOT cache pages or API responses — caching them
|
||||
// would only cause stale-data bugs after an AppImage update.
|
||||
//
|
||||
// The install / activate handlers clean up old SW caches from
|
||||
// previous Monitor versions so a beta-to-stable upgrade never
|
||||
// strands the browser on a cached old shell.
|
||||
// The install / activate handlers wipe every cache in Cache
|
||||
// Storage (no allow-list) so stale entries from any previous
|
||||
// Monitor version — including ones that shared this SW's
|
||||
// version name — cannot survive an upgrade and haunt the
|
||||
// dashboard as frozen `/api/*` responses.
|
||||
// ==========================================================
|
||||
|
||||
const SW_VERSION = 'proxmenux-monitor-v1';
|
||||
const SW_VERSION = 'proxmenux-monitor-v2';
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
// Take over as soon as installed; no skipWaiting handshake.
|
||||
@@ -22,12 +24,19 @@ self.addEventListener('install', (event) => {
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil((async () => {
|
||||
// Wipe any cache name that isn't ours — survives renames /
|
||||
// version bumps without piling up stale entries.
|
||||
const names = await caches.keys();
|
||||
await Promise.all(
|
||||
names.filter((n) => n !== SW_VERSION).map((n) => caches.delete(n))
|
||||
);
|
||||
// Scorched earth: wipe EVERY cache, regardless of name. This
|
||||
// SW never writes to Cache Storage, so nothing here should
|
||||
// ever be authoritative. The previous version kept caches
|
||||
// that matched SW_VERSION exactly, which stranded old cached
|
||||
// /api/* responses across upgrades and manifested as a
|
||||
// dashboard that never refreshed until the user manually
|
||||
// cleared Cache Storage from DevTools.
|
||||
try {
|
||||
const names = await caches.keys();
|
||||
await Promise.all(names.map((n) => caches.delete(n)));
|
||||
} catch (_) {
|
||||
// caches API unavailable — nothing to clean.
|
||||
}
|
||||
await self.clients.claim();
|
||||
})());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user