Exclude local media requests

This commit is contained in:
tusooa 2023-05-26 16:37:06 -04:00
commit ed04c2ac71
No known key found for this signature in database
GPG key ID: 42AEC43D48433C51

View file

@ -97,6 +97,15 @@ const isEmoji = req => {
return url.pathname.startsWith('/emoji/') 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) => { self.addEventListener('install', async (event) => {
if (shouldCache) { if (shouldCache) {
@ -184,7 +193,7 @@ self.addEventListener('notificationclick', (event) => {
self.addEventListener('fetch', (event) => { self.addEventListener('fetch', (event) => {
// Do not mess up with remote things // Do not mess up with remote things
const isSameOrigin = (new URL(event.request.url)).origin === self.location.origin 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 () => { event.respondWith((async () => {
const r = await caches.match(event.request) const r = await caches.match(event.request)