a fork of iceshrimp.net but a tweaked frontend to my personal liking. waow
fediverse social-media social iceshrimp fedi
0
fork

Configure Feed

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

[frontend] Do not intercept fetches for un-cached requests

Kopper 252a6386 d8efbf09

+14 -4
+14 -4
Iceshrimp.Frontend/wwwroot/service-worker.published.js
··· 4 4 self.importScripts('./service-worker-assets.js'); 5 5 self.addEventListener('install', event => event.waitUntil(onInstall(event))); 6 6 self.addEventListener('activate', event => event.waitUntil(onActivate(event))); 7 - self.addEventListener('fetch', event => event.respondWith(onFetch(event))); 7 + self.addEventListener('fetch', event => { 8 + if (!shouldFetch(event.request.url)) return; 9 + event.respondWith(onFetch(event)); 10 + }); 8 11 9 12 const cacheNamePrefix = 'offline-cache-'; 10 13 const cacheName = `${cacheNamePrefix}${self.assetsManifest.version}`; ··· 24 27 25 28 // Fetch and cache all matching items from the assets manifest 26 29 const assetsRequests = self.assetsManifest.assets 27 - .filter(asset => offlineAssetsInclude.some(pattern => pattern.test(asset.url))) 28 - .filter(asset => !offlineAssetsExclude.some(pattern => pattern.test(asset.url))) 30 + .filter(asset => shouldFetch(asset.url)) 29 31 .map(asset => new Request(asset.url, {integrity: asset.hash, cache: 'no-cache'})); 30 32 await caches.open(cacheName).then(cache => cache.addAll(assetsRequests)); 31 33 } ··· 40 42 .map(key => caches.delete(key))); 41 43 } 42 44 45 + /** @param {url} string */ 46 + function shouldFetch(url) { 47 + if (offlineAssetsInclude.some(pattern => !pattern.test(url))) return false; 48 + if (offlineAssetsExclude.some(pattern => pattern.test(url))) return false; 49 + 50 + return true; 51 + } 52 + 43 53 async function onFetch(event) { 44 54 let cachedResponse = null; 45 55 if (event.request.method === 'GET') { ··· 54 64 cachedResponse = await cache.match(request); 55 65 } 56 66 57 - return cachedResponse || fetch(event.request); 67 + return cachedResponse; 58 68 } 59 69 60 70 self.addEventListener('message', (event) => {