11export const serviceWorker = ( ) => `
2+ const EXTENSIONS_WITH_PREVIEW = new Set([
3+ 'jpg',
4+ 'jpeg',
5+ 'png',
6+ 'gif',
7+ 'webp',
8+ 'ico',
9+ 'avif',
10+ ])
211self.addEventListener('fetch', event => {
312 const url = new URL(event.request.url);
413 const isSameDomain = url.origin === self.location.origin;
@@ -7,18 +16,19 @@ self.addEventListener('fetch', event => {
716 return event.respondWith(fetch(event.request));
817 }
918
10- if (url.pathname.startsWith('/_ipx/_/') || ['jpg', 'png', 'jpeg', 'gif', 'webp'].includes (url.pathname.split('.').pop())) {
19+ if (url.pathname.startsWith('/_ipx/_/') || EXTENSIONS_WITH_PREVIEW.has (url.pathname.split('.').pop())) {
1120 console.log('Fetching from IndexedDB:', url.pathname);
1221 return event.respondWith(fetchFromIndexedDB(event, url));
1322 }
1423
1524 event.respondWith(fetch(event.request))
1625})
1726
18- function fetchFromIndexedDB(event,url) {
19- const dbKey = ['public-assets:', url.pathname.replace('/ _ipx/_/' , '').replace('/', ':')].join('')
27+ function fetchFromIndexedDB(event, url) {
28+ const dbKey = ['public-assets:', url.pathname.replace(/^\\/+( _ipx\\/_\\/)?/ , '').replace('/', ':')].join('')
2029 return getData(dbKey).then(data => {
2130 if (!data) {
31+ console.log('No data found in IndexedDB:', url.pathnam, dbKey);
2232 return fetch(event.request);
2333 }
2434
0 commit comments