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

BIN
public/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 KiB

View File

@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -8,7 +9,11 @@
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;500;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<link rel="manifest" href="manifest.json">
<meta name="theme-color" content="#FF6B6B">
<link rel="apple-touch-icon" href="icon.png">
</head>
<body>
<div class="app-container">
<header>
@@ -45,5 +50,15 @@
<script src="/socket.io/socket.io.js"></script>
<script src="client.js"></script>
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js')
.then(reg => console.log('SW Registered!', reg.scope))
.catch(err => console.log('SW Failed:', err));
});
}
</script>
</body>
</html>
</html>

21
public/manifest.json Normal file
View File

@@ -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"
}
]
}

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);
}
})
);
})
);
});