Initial commit

This commit is contained in:
Porawit Dongwang
2026-09-16 23:20:08 +07:00
commit 0041668dbb
32577 changed files with 3687927 additions and 0 deletions
@@ -0,0 +1,50 @@
const CACHE_NAME = 'samui-hospital-cache-v1';
const urlsToCache = [
'./index.php',
'./category.php',
'./assets/img/logo_MOPH.png'
];
// ติดตั้ง Service Worker และ Caching ไฟล์พื้นฐาน
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
return cache.addAll(urlsToCache);
})
);
});
// ฟังเหตุการณ์ Fetch (ดึงจาก Cache ถ้าออฟไลน์)
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
if (response) {
return response; // คืนค่าจาก Cache
}
return fetch(event.request).catch(() => {
// ถ้า offline และดึงไฟล์ไม่ได้
if (event.request.mode === 'navigate') {
return caches.match('./index.php');
}
});
})
);
});
// จัดการลบ Cache เก่าเมื่อมีการอัปเดต Service Worker
self.addEventListener('activate', event => {
const cacheWhitelist = [CACHE_NAME];
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
if (cacheWhitelist.indexOf(cacheName) === -1) {
return caches.delete(cacheName);
}
})
);
})
);
});