Exclude local media requests
This commit is contained in:
parent
6ab98db7ad
commit
ed04c2ac71
1 changed files with 10 additions and 1 deletions
11
src/sw.js
11
src/sw.js
|
|
@ -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)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue