From 933bb08947a61448abfebc85dbaa2b7daabf130e Mon Sep 17 00:00:00 2001 From: Azamat Mambetov Date: Sun, 14 Apr 2024 12:19:27 +0000 Subject: [PATCH 1/3] fix(cache): avoid caching large files --- assets/js/pwa/sw.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/pwa/sw.js b/assets/js/pwa/sw.js index adc707ef9fb..7e8a30b2e0d 100644 --- a/assets/js/pwa/sw.js +++ b/assets/js/pwa/sw.js @@ -84,7 +84,7 @@ self.addEventListener('fetch', (event) => { return fetch(event.request).then((response) => { const url = event.request.url; - if (purge || event.request.method !== 'GET' || !verifyUrl(url)) { + if (purge || response.status !== 200 || event.request.method !== 'GET' || !verifyUrl(url)) { return response; } From 52e199c27d5fbe682ae15b529f9f203626fa6bd6 Mon Sep 17 00:00:00 2001 From: Azamat Mambetov Date: Mon, 29 Apr 2024 13:33:58 +0000 Subject: [PATCH 2/3] fix: change the condition to do it more strict (status code is 206) --- assets/js/pwa/sw.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/pwa/sw.js b/assets/js/pwa/sw.js index 7e8a30b2e0d..fa9503ff307 100644 --- a/assets/js/pwa/sw.js +++ b/assets/js/pwa/sw.js @@ -84,7 +84,7 @@ self.addEventListener('fetch', (event) => { return fetch(event.request).then((response) => { const url = event.request.url; - if (purge || response.status !== 200 || event.request.method !== 'GET' || !verifyUrl(url)) { + if (purge || response.status === 206 || event.request.method !== 'GET' || !verifyUrl(url)) { return response; } From 48d4bbf357d2de70a9bc7a44cc161af4ebcad12b Mon Sep 17 00:00:00 2001 From: Azamat Mambetov Date: Mon, 29 Apr 2024 15:17:52 +0000 Subject: [PATCH 3/3] fix: remove strict checking and avoid range request --- assets/js/pwa/sw.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/assets/js/pwa/sw.js b/assets/js/pwa/sw.js index fa9503ff307..dbf30f476ac 100644 --- a/assets/js/pwa/sw.js +++ b/assets/js/pwa/sw.js @@ -75,6 +75,10 @@ self.addEventListener('message', (event) => { }); self.addEventListener('fetch', (event) => { + if (event.request.headers.has('range')) { + return; + } + event.respondWith( caches.match(event.request).then((response) => { if (response) { @@ -84,7 +88,7 @@ self.addEventListener('fetch', (event) => { return fetch(event.request).then((response) => { const url = event.request.url; - if (purge || response.status === 206 || event.request.method !== 'GET' || !verifyUrl(url)) { + if (purge || event.request.method !== 'GET' || !verifyUrl(url)) { return response; }