46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
// Minimal PWA service worker with no API caching
|
|
|
|
self.addEventListener("install", (event) => {
|
|
// Skip waiting so updated SW takes control faster
|
|
// but we do not pre-cache anything to keep behavior minimal
|
|
// @ts-ignore
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
// Claim clients so the SW starts controlling pages immediately
|
|
// @ts-ignore
|
|
event.waitUntil(self.clients.claim());
|
|
});
|
|
|
|
self.addEventListener("fetch", (event) => {
|
|
const request = event.request;
|
|
|
|
// Do not cache anything; just let the request pass through.
|
|
// Especially do not touch API requests.
|
|
// If needed in future, add logic here, but keep it disabled for now.
|
|
return;
|
|
});
|
|
|
|
self.addEventListener('push', function(event) {
|
|
if (event.data) {
|
|
const payload = event.data.json();
|
|
const title = payload.title || 'New Notification';
|
|
const options = {
|
|
body: payload.body,
|
|
icon: payload.icon || '/favicon.png',
|
|
badge: payload.badge || '/favicon.png',
|
|
data: payload.url || '/'
|
|
};
|
|
|
|
event.waitUntil(self.registration.showNotification(title, options));
|
|
}
|
|
});
|
|
|
|
self.addEventListener('notificationclick', function(event) {
|
|
event.notification.close();
|
|
event.waitUntil(
|
|
clients.openWindow(event.notification.data)
|
|
);
|
|
});
|