48 lines
1.4 KiB
JavaScript
48 lines
1.4 KiB
JavaScript
const CACHE_NAME = 'hms-opd-queue-v2';
|
|
const ASSETS_TO_CACHE = [
|
|
'/App/Queue/manifest.json',
|
|
'/assets/img/logo.png',
|
|
'/assets/img/pwa-icon-512.png',
|
|
'/assets/img/pwa-icon-192.png',
|
|
'https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css',
|
|
'https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css'
|
|
];
|
|
|
|
self.addEventListener('install', (event) => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME).then((cache) => {
|
|
return cache.addAll(ASSETS_TO_CACHE);
|
|
})
|
|
);
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener('activate', (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then((keys) => {
|
|
return Promise.all(
|
|
keys.map((key) => {
|
|
if (key !== CACHE_NAME) {
|
|
return caches.delete(key);
|
|
}
|
|
})
|
|
);
|
|
})
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
self.addEventListener('fetch', (event) => {
|
|
// Navigation requests (HTML documents) and API endpoints must always go straight to network
|
|
if (event.request.mode === 'navigate' || event.request.url.includes('/api/v1/') || event.request.url.includes('/app/queue')) {
|
|
event.respondWith(fetch(event.request));
|
|
return;
|
|
}
|
|
|
|
event.respondWith(
|
|
caches.match(event.request).then((cachedResponse) => {
|
|
return cachedResponse || fetch(event.request);
|
|
})
|
|
);
|
|
});
|