From ed04c2ac710cb51f01d34efcfdf8d007fa764c16 Mon Sep 17 00:00:00 2001 From: tusooa Date: Fri, 26 May 2023 16:37:06 -0400 Subject: [PATCH] Exclude local media requests --- src/sw.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/sw.js b/src/sw.js index 87eb484a5..c53927a32 100644 --- a/src/sw.js +++ b/src/sw.js @@ -97,6 +97,15 @@ const isEmoji = req => { return url.pathname.startsWith('/emoji/') } +const isNotMedia = req => { + console.log('req.method=', req.method) + if (req.method !== 'GET') { + return false + } + const url = new URL(req.url) + console.log('pathname=', url.pathname) + return !url.pathname.startsWith('/media/') +} self.addEventListener('install', async (event) => { if (shouldCache) { @@ -184,7 +193,7 @@ self.addEventListener('notificationclick', (event) => { self.addEventListener('fetch', (event) => { // Do not mess up with remote things const isSameOrigin = (new URL(event.request.url)).origin === self.location.origin - if (shouldCache && event.request.method === 'GET' && isSameOrigin) { + if (shouldCache && event.request.method === 'GET' && isSameOrigin && isNotMedia(event.request)) { event.respondWith((async () => { const r = await caches.match(event.request)