This commit is contained in:
2026-01-11 00:01:51 +00:00
parent 344066fb51
commit c0fb8d611b
4 changed files with 79 additions and 1 deletions

42
public/sw.js Normal file
View File

@@ -0,0 +1,42 @@
const CACHE_NAME = 'global-counter-v1';
const ASSETS = [
'/',
'/index.html',
'/style.css',
'/client.js',
'/icon.png',
'/manifest.json'
];
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME)
.then((cache) => cache.addAll(ASSETS))
);
});
self.addEventListener('fetch', (event) => {
// For Socket.io or Admin, go to network
if (event.request.url.includes('/socket.io/') || event.request.url.includes('/admin')) {
return;
}
event.respondWith(
caches.match(event.request)
.then((response) => response || fetch(event.request))
);
});
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((cacheNames) => {
return Promise.all(
cacheNames.map((cacheName) => {
if (cacheName !== CACHE_NAME) {
return caches.delete(cacheName);
}
})
);
})
);
});