- Web app manifest with name, icons, theme color, standalone display - Service worker with stale-while-revalidate caching strategy - 192px and 512px PNG icons generated from favicon.svg - Apple-specific meta tags for iOS home screen support - Register service worker on page load Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
34 lines
824 B
JavaScript
34 lines
824 B
JavaScript
const CACHE_NAME = 'reaktor-v1';
|
|
|
|
self.addEventListener('install', (e) => {
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener('activate', (e) => {
|
|
e.waitUntil(
|
|
caches.keys().then(keys =>
|
|
Promise.all(keys.filter(k => k !== CACHE_NAME).map(k => caches.delete(k)))
|
|
)
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
self.addEventListener('fetch', (e) => {
|
|
// Only cache GET requests, skip API calls
|
|
if (e.request.method !== 'GET') return;
|
|
|
|
e.respondWith(
|
|
caches.match(e.request).then(cached => {
|
|
const fetching = fetch(e.request).then(response => {
|
|
if (response.ok) {
|
|
const clone = response.clone();
|
|
caches.open(CACHE_NAME).then(cache => cache.put(e.request, clone));
|
|
}
|
|
return response;
|
|
}).catch(() => cached);
|
|
|
|
return cached || fetching;
|
|
})
|
|
);
|
|
});
|