36 lines
839 B
JavaScript
36 lines
839 B
JavaScript
// Service Worker for FlockRadar Offline Driving & Caching
|
|
const CACHE_NAME = 'flockradar-v2';
|
|
const ASSETS_TO_CACHE = [
|
|
'./',
|
|
'./index.html',
|
|
'./css/styles.css',
|
|
'./js/app.js',
|
|
'./js/auth.js',
|
|
'./js/radar.js',
|
|
'./data/portals.js',
|
|
'./manifest.json'
|
|
];
|
|
|
|
self.addEventListener('install', event => {
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME).then(cache => cache.addAll(ASSETS_TO_CACHE))
|
|
);
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener('activate', event => {
|
|
event.waitUntil(
|
|
caches.keys().then(keys => Promise.all(
|
|
keys.filter(key => key !== CACHE_NAME).map(key => caches.delete(key))
|
|
))
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
self.addEventListener('fetch', event => {
|
|
// Network first, fallback to cache
|
|
event.respondWith(
|
|
fetch(event.request).catch(() => caches.match(event.request))
|
|
);
|
|
});
|