37 lines
699 B
JavaScript
37 lines
699 B
JavaScript
|
|
const CACHE_NAME = 'clinic-app-cache-v1';
|
|
const urlsToCache = [
|
|
'/',
|
|
'/index.php',
|
|
'/dashboard.php',
|
|
'/login.php',
|
|
'/register.php',
|
|
'/view_visits.php',
|
|
'/add_visit.php',
|
|
'/auth.php',
|
|
'/logout.php',
|
|
'/update_visit_status.php'
|
|
];
|
|
|
|
self.addEventListener('install', event => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME)
|
|
.then(cache => {
|
|
console.log('Opened cache');
|
|
return cache.addAll(urlsToCache);
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener('fetch', event => {
|
|
event.respondWith(
|
|
caches.match(event.request)
|
|
.then(response => {
|
|
if (response) {
|
|
return response;
|
|
}
|
|
return fetch(event.request);
|
|
})
|
|
);
|
|
});
|