From 2cfc36ce0d5e10415781d6add14f064ff9cb85e8 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 18 Apr 2018 01:22:55 +0200 Subject: [PATCH] Cache the correct content types --- scripts/ServiceWorker/ServiceWorker.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/ServiceWorker/ServiceWorker.ts b/scripts/ServiceWorker/ServiceWorker.ts index e18f6825..f334741c 100644 --- a/scripts/ServiceWorker/ServiceWorker.ts +++ b/scripts/ServiceWorker/ServiceWorker.ts @@ -62,12 +62,6 @@ class MyServiceWorker { // Chrome extension "chrome-extension", - // Media files - ".webm", - ".opus", - ".ogg", - ".m4a", - // Authorization paths /auth/ and /logout are not listed here because they are handled in a special way. ]) @@ -168,7 +162,14 @@ class MyServiceWorker { // -------------------------------------------------------------------------------- // Save response in cache. - let saveResponseInCache = response => { + let saveResponseInCache = (response: Response) => { + let contentType = response.headers.get("Content-Type") + + // Don't cache anything other than text and images. + if(!contentType.includes("text/") && !contentType.includes("application/javascript") && !contentType.includes("image/")) { + return response + } + // Save response in cache. let clone = response.clone() this.cache.store(request, clone)