devsofttech_hms_ci4/public/App/Queue/sw.js

50 lines
1.4 KiB
JavaScript

const CACHE_NAME = 'hms-opd-queue-v1';
const ASSETS_TO_CACHE = [
'/app/queue',
'/App/Queue/index.html',
'/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) => {
// API endpoints always fetch fresh network data
if (event.request.url.includes('/api/v1/')) {
event.respondWith(fetch(event.request));
return;
}
event.respondWith(
caches.match(event.request).then((cachedResponse) => {
return cachedResponse || fetch(event.request);
})
);
});