diff --git a/src/hooks/useImageCache.ts b/src/hooks/useImageCache.ts index 6d93fe41..975ff7fb 100644 --- a/src/hooks/useImageCache.ts +++ b/src/hooks/useImageCache.ts @@ -10,6 +10,8 @@ export function useImageCache( imageUrl: string | undefined ): string | undefined { // Service Worker handles everything - just return the URL as-is + // The Service Worker will intercept fetch requests and cache them + // Make sure images use standard tags for SW interception return imageUrl } diff --git a/src/services/imageCacheService.ts b/src/services/imageCacheService.ts index e35a9b4a..b68a38a7 100644 --- a/src/services/imageCacheService.ts +++ b/src/services/imageCacheService.ts @@ -5,7 +5,8 @@ * Service Worker automatically caches images on fetch */ -const CACHE_NAME = 'boris-image-cache-v1' +// Must match the cache name in src/sw.ts +const CACHE_NAME = 'boris-images' /** * Clear all cached images diff --git a/src/sw.ts b/src/sw.ts index 5bcf5f0c..9bc45176 100644 --- a/src/sw.ts +++ b/src/sw.ts @@ -23,13 +23,15 @@ sw.skipWaiting() clientsClaim() -// Runtime cache: Cross-origin images -// This preserves the existing image caching behavior +// Runtime cache: All images (cross-origin and same-origin) +// Cache both external images and any internal image assets registerRoute( ({ request, url }) => { const isImage = request.destination === 'image' || /\.(jpg|jpeg|png|gif|webp|svg)$/i.test(url.pathname) - return isImage && url.origin !== sw.location.origin + // Cache all images, not just cross-origin ones + // This ensures article images from any source get cached + return isImage }, new StaleWhileRevalidate({ cacheName: 'boris-images',