Files
aitbc/website/assets/js/sw.js
oib 15427c96c0 chore: update file permissions to executable across repository
- Change file mode from 644 to 755 for all project files
- Add chain_id parameter to get_balance RPC endpoint with default "ait-devnet"
- Rename Miner.extra_meta_data to extra_metadata for consistency
2026-03-06 22:17:54 +01:00

70 lines
1.8 KiB
JavaScript
Executable File

const CACHE_NAME = 'aitbc-v1';
const urlsToCache = [
'/',
'/index.html',
'/assets/css/main.css',
'/assets/css/font-awesome.min.css',
'/assets/js/main.js',
'/favicon.ico',
'/explorer/',
'/marketplace/',
'/docs/'
];
// Install event - cache assets
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
console.log('Caching assets...');
return cache.addAll(urlsToCache);
})
.catch(err => console.log('Cache failed:', err))
);
self.skipWaiting();
});
// Fetch event - serve from cache or network
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
// Return cached version or fetch from network
if (response) {
return response;
}
return fetch(event.request)
.then(networkResponse => {
// Cache successful network responses
if (networkResponse && networkResponse.status === 200) {
const clonedResponse = networkResponse.clone();
caches.open(CACHE_NAME).then(cache => {
cache.put(event.request, clonedResponse);
});
}
return networkResponse;
})
.catch(() => {
// Return offline fallback for HTML requests
if (event.request.mode === 'navigate') {
return caches.match('/index.html');
}
});
})
);
});
// Activate event - clean up old caches
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames
.filter(name => name !== CACHE_NAME)
.map(name => caches.delete(name))
);
})
);
self.clients.claim();
});