puteroapix / public /sw-register.js
woiceatus's picture
imrpove ui for chatclient
adb34c2
raw
history blame contribute delete
619 Bytes
export async function registerServiceWorker() {
if (!("serviceWorker" in navigator)) {
return;
}
try {
const registrations = await navigator.serviceWorker.getRegistrations();
await Promise.all(registrations.map((registration) => registration.unregister()));
if ("caches" in window) {
const cacheNames = await window.caches.keys();
await Promise.all(
cacheNames
.filter((name) => name.startsWith("oapix-static"))
.map((name) => window.caches.delete(name))
);
}
} catch (error) {
console.error("service worker cleanup failed", error);
}
}