mirror of
https://github.com/dergigi/boris.git
synced 2026-02-01 05:04:29 +01:00
chore: remove all debug console output from article cache and service worker
Remove all console.log, console.warn, and console.error statements that were added for debugging in article cache, service worker, and image caching code.
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
// Development Service Worker - simplified version for testing image caching
|
||||
// This is served in dev mode when vite-plugin-pwa doesn't serve the injectManifest SW
|
||||
|
||||
console.log('[sw-dev] Development Service Worker loaded')
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
console.log('[sw-dev] Installing...')
|
||||
self.skipWaiting()
|
||||
})
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
console.log('[sw-dev] Activating...')
|
||||
event.waitUntil(clients.claim())
|
||||
})
|
||||
|
||||
@@ -20,26 +16,18 @@ self.addEventListener('fetch', (event) => {
|
||||
/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(url.pathname)
|
||||
|
||||
if (isImage) {
|
||||
console.log('[sw-dev] Intercepting image:', url.href)
|
||||
|
||||
event.respondWith(
|
||||
caches.open('boris-images-dev').then((cache) => {
|
||||
return cache.match(event.request).then((cachedResponse) => {
|
||||
if (cachedResponse) {
|
||||
console.log('[sw-dev] ✅ Serving from cache:', url.href)
|
||||
return cachedResponse
|
||||
}
|
||||
|
||||
console.log('[sw-dev] Fetching from network:', url.href)
|
||||
return fetch(event.request).then((response) => {
|
||||
if (response.ok) {
|
||||
console.log('[sw-dev] Caching response:', url.href)
|
||||
cache.put(event.request, response.clone())
|
||||
}
|
||||
return response
|
||||
}).catch((err) => {
|
||||
console.error('[sw-dev] Fetch failed:', url.href, err)
|
||||
throw err
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -47,5 +35,3 @@ self.addEventListener('fetch', (event) => {
|
||||
}
|
||||
})
|
||||
|
||||
console.log('[sw-dev] Development Service Worker ready')
|
||||
|
||||
|
||||
@@ -41,11 +41,6 @@ export function preloadImage(imageUrl: string | undefined): void {
|
||||
// Create a link element with rel=prefetch or use Image object to trigger fetch
|
||||
// Service Worker will intercept and cache the request
|
||||
const img = new Image()
|
||||
|
||||
img.onerror = (err) => {
|
||||
console.error('[image-preload] Failed to load image:', imageUrl, err)
|
||||
}
|
||||
|
||||
img.src = imageUrl
|
||||
|
||||
// Also try using fetch to explicitly trigger Service Worker
|
||||
|
||||
@@ -52,7 +52,7 @@ export function getFromCache(naddr: string): ArticleContent | null {
|
||||
|
||||
return content
|
||||
} catch (err) {
|
||||
console.warn('[article-cache] Error reading cache:', err)
|
||||
// Silently handle cache read errors
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -86,7 +86,6 @@ export function cacheArticleEvent(event: NostrEvent, settings?: UserSettings): v
|
||||
saveToCache(naddr, articleContent, settings)
|
||||
} catch (err) {
|
||||
// Silently fail cache saves - quota exceeded, invalid data, etc.
|
||||
console.warn('[article-cache] Failed to cache article event:', err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,16 +104,8 @@ export function saveToCache(naddr: string, content: ArticleContent, settings?: U
|
||||
}
|
||||
localStorage.setItem(cacheKey, JSON.stringify(cached))
|
||||
} catch (err) {
|
||||
// Handle quota exceeded errors specifically
|
||||
if (err instanceof DOMException && (err.code === 22 || err.code === 1014 || err.name === 'QuotaExceededError')) {
|
||||
console.warn('[article-cache] ⚠️ Storage quota exceeded - article not cached:', {
|
||||
title: content.title,
|
||||
error: err.message
|
||||
})
|
||||
} else {
|
||||
console.warn('[article-cache] Failed to cache article:', err)
|
||||
}
|
||||
// Silently fail - don't block the UI if caching fails
|
||||
// Handles quota exceeded, invalid data, and other errors gracefully
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
27
src/sw.ts
27
src/sw.ts
@@ -31,15 +31,6 @@ registerRoute(
|
||||
/\.(jpg|jpeg|png|gif|webp|svg)$/i.test(url.pathname)
|
||||
// Cache all images, not just cross-origin ones
|
||||
// This ensures article images from any source get cached
|
||||
|
||||
if (isImage) {
|
||||
console.log('[sw-image-cache] Intercepting image request:', {
|
||||
url: url.href,
|
||||
destination: request.destination,
|
||||
method: request.method
|
||||
})
|
||||
}
|
||||
|
||||
return isImage
|
||||
},
|
||||
new StaleWhileRevalidate({
|
||||
@@ -53,26 +44,8 @@ registerRoute(
|
||||
statuses: [0, 200],
|
||||
}),
|
||||
{
|
||||
cacheKeyWillBeUsed: async ({ request }) => {
|
||||
console.log('[sw-image-cache] Cache key generated for:', request.url)
|
||||
return request
|
||||
},
|
||||
cacheWillUpdate: async ({ response }) => {
|
||||
console.log('[sw-image-cache] Caching response:', {
|
||||
url: response.url,
|
||||
status: response.status,
|
||||
type: response.type,
|
||||
ok: response.ok
|
||||
})
|
||||
return response.ok ? response : null
|
||||
},
|
||||
cachedResponseWillBeUsed: async ({ cachedResponse, request }) => {
|
||||
if (cachedResponse) {
|
||||
console.log('[sw-image-cache] ✅ Serving from cache:', request.url)
|
||||
} else {
|
||||
console.log('[sw-image-cache] ❌ No cached response found:', request.url)
|
||||
}
|
||||
return cachedResponse || null
|
||||
}
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user