diff --git a/public/icon.png b/public/icon.png new file mode 100644 index 0000000..beb4be2 Binary files /dev/null and b/public/icon.png differ diff --git a/public/index.html b/public/index.html index 747debe..9426f76 100644 --- a/public/index.html +++ b/public/index.html @@ -1,5 +1,6 @@ + @@ -8,7 +9,11 @@ + + + +
@@ -45,5 +50,15 @@ + - + + \ No newline at end of file diff --git a/public/manifest.json b/public/manifest.json new file mode 100644 index 0000000..572571b --- /dev/null +++ b/public/manifest.json @@ -0,0 +1,21 @@ +{ + "name": "Global Counter", + "short_name": "Counter", + "description": "A real-time global counter application.", + "start_url": "/", + "display": "standalone", + "background_color": "#F0F2F5", + "theme_color": "#FF6B6B", + "icons": [ + { + "src": "icon.png", + "sizes": "512x512", + "type": "image/png" + }, + { + "src": "icon.png", + "sizes": "192x192", + "type": "image/png" + } + ] +} \ No newline at end of file diff --git a/public/sw.js b/public/sw.js new file mode 100644 index 0000000..fa10fc1 --- /dev/null +++ b/public/sw.js @@ -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); + } + }) + ); + }) + ); +});