this repo has no description
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat: always load cache if it exists

+23 -13
+23 -13
mast-react-vite/public/service-worker.js
··· 245 245 246 246 // Default strategy for navigation and other requests 247 247 async function defaultStrategy(request) { 248 - // For navigation requests, try network first then fall back to cache 248 + // For navigation requests, serve from cache first (local-first) 249 249 if (request.mode === 'navigate') { 250 + const cache = await caches.open(STATIC_CACHE); 251 + const cachedResponse = await cache.match(request); 252 + 253 + if (cachedResponse) { 254 + // Serve from cache immediately 255 + console.log('[Service Worker] Serving navigation from cache (local-first):', request.url); 256 + 257 + // Update cache in background (don't await) 258 + fetch(request).then(networkResponse => { 259 + if (networkResponse.ok) { 260 + cache.put(request, networkResponse.clone()); 261 + console.log('[Service Worker] Updated cache in background:', request.url); 262 + } 263 + }).catch(error => { 264 + console.log('[Service Worker] Background update failed:', request.url); 265 + }); 266 + 267 + return cachedResponse; 268 + } 269 + 270 + // If no cached version, try network 250 271 try { 251 - // Try network first for fresh content 252 272 const networkResponse = await fetch(request); 253 - // Cache the response for future use 254 - const cache = await caches.open(STATIC_CACHE); 255 273 cache.put(request, networkResponse.clone()); 256 274 return networkResponse; 257 275 } catch (error) { 258 - // If network fails, try to serve from cache 259 - const cache = await caches.open(STATIC_CACHE); 260 - const cachedResponse = await cache.match(request); 261 - 262 - if (cachedResponse) { 263 - return cachedResponse; 264 - } 265 - 266 - // If no cached version, show offline page 276 + // If network also fails, show offline page 267 277 return caches.match('/offline.html'); 268 278 } 269 279 }