| Server IP : 167.235.67.158 / Your IP : 216.73.217.114 Web Server : Apache System : Linux ubuntu-8gb-nbg1-1 6.8.0-111-generic #111-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 11 23:16:02 UTC 2026 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/bc.the-word.com/ |
Upload File : |
/**
* Service Worker for 2026 Challenge Calendar
* Enables offline functionality and caching
*/
const CACHE_NAME = '2026-challenges-v1';
const ASSETS_TO_CACHE = [
'/',
'/index.html',
'/styles.css',
'/app.js',
'/challenges.json',
'/manifest.json',
'/icons/icon-192.png',
'/icons/icon-512.png',
'/icons/apple-touch-icon.png'
];
// Install event - cache assets
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME)
.then((cache) => {
console.log('Caching app assets');
return cache.addAll(ASSETS_TO_CACHE);
})
.then(() => {
// Activate immediately
return self.skipWaiting();
})
);
});
// Activate event - clean up old caches
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys()
.then((cacheNames) => {
return Promise.all(
cacheNames.map((cacheName) => {
if (cacheName !== CACHE_NAME) {
console.log('Deleting old cache:', cacheName);
return caches.delete(cacheName);
}
})
);
})
.then(() => {
// Take control of all pages immediately
return self.clients.claim();
})
);
});
// Fetch event - serve from cache, fallback to network
self.addEventListener('fetch', (event) => {
// Skip non-GET requests
if (event.request.method !== 'GET') {
return;
}
event.respondWith(
caches.match(event.request)
.then((cachedResponse) => {
if (cachedResponse) {
// Return cached version
return cachedResponse;
}
// Not in cache - fetch from network
return fetch(event.request)
.then((networkResponse) => {
// Don't cache if not a valid response
if (!networkResponse || networkResponse.status !== 200 || networkResponse.type !== 'basic') {
return networkResponse;
}
// Clone the response (can only be consumed once)
const responseToCache = networkResponse.clone();
// Add to cache for future use
caches.open(CACHE_NAME)
.then((cache) => {
cache.put(event.request, responseToCache);
});
return networkResponse;
})
.catch(() => {
// Network failed and not in cache
// Return a fallback for HTML pages
if (event.request.headers.get('accept').includes('text/html')) {
return caches.match('/index.html');
}
});
})
);
});
// Handle messages from the main app
self.addEventListener('message', (event) => {
if (event.data.action === 'skipWaiting') {
self.skipWaiting();
}
});