Something went wrong. Try again.
Central platform for European atproto.<cc> country community websites atproto.eu
community atproto
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556// Minimal service worker: offline fallback + cache-first for fingerprinted static assets.// Pages are network-first (fresh when online, cached when offline, then an offline page).// Deliberately does NOT cache OAuth / client-metadata / XRPC — those must always hit the network.const CACHE = 'atproto-nl-v2';const OFFLINE = '/offline';
self.addEventListener('install', (e) => { e.waitUntil(caches.open(CACHE).then((c) => c.addAll(['/', OFFLINE])).then(() => self.skipWaiting()));});
self.addEventListener('activate', (e) => { e.waitUntil( caches .keys() .then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))) .then(() => self.clients.claim()), );});
self.addEventListener('fetch', (e) => { const req = e.request; if (req.method !== 'GET') return; const url = new URL(req.url); if (url.origin !== location.origin) return;
// Page navigations: network-first, fall back to cache, then the offline page. if (req.mode === 'navigate') { e.respondWith( fetch(req) .then((res) => { const copy = res.clone(); caches.open(CACHE).then((c) => c.put(req, copy)); return res; }) .catch(() => caches.match(req).then((r) => r || caches.match(OFFLINE))), ); return; }
// Fingerprinted static assets: cache-first (safe — the URL changes when the content changes). if (url.pathname.startsWith('/_astro/') || /\.(?:woff2?|png|webp|svg|ico|jpg|jpeg|gif)$/.test(url.pathname)) { e.respondWith( caches.match(req).then( (r) => r || fetch(req).then((res) => { const copy = res.clone(); caches.open(CACHE).then((c) => c.put(req, copy)); return res; }), ), ); } // Everything else (client-metadata.json, XRPC, etc.) falls through to the network.});