about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/javascript/mastodon/service_worker/entry.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/app/javascript/mastodon/service_worker/entry.js b/app/javascript/mastodon/service_worker/entry.js
index 9a3911b2a..d28a2be6d 100644
--- a/app/javascript/mastodon/service_worker/entry.js
+++ b/app/javascript/mastodon/service_worker/entry.js
@@ -13,6 +13,8 @@ function fetchRoot() {
   return fetch('/', { credentials: 'include' });
 }
 
+const invalidOnlyIfCached = navigator.userAgent.match(/Firefox\/(\d+)/)[1] < 60;
+
 // Cause a new version of a registered Service Worker to replace an existing one
 // that is already installed, and replace the currently active worker on open pages.
 self.addEventListener('install', function(event) {
@@ -54,19 +56,22 @@ self.addEventListener('fetch', function(event) {
     event.respondWith(openSystemCache().then(cache => {
       return cache.match(event.request.url).then(cached => {
         if (cached === undefined) {
-          return fetch(event.request).then(fetched => {
-            if (fetched.ok) {
-              const put = cache.put(event.request.url, fetched.clone());
+          const asyncResponse = invalidOnlyIfCached && event.request.cache === 'only-if-cached' ?
+            fetch(event.request, { cache: 'no-cache' }) : fetch(event.request);
+
+          return asyncResponse.then(response => {
+            if (response.ok) {
+              const put = cache.put(event.request.url, response.clone());
 
               put.catch(() => freeStorage());
 
               return put.then(() => {
                 freeStorage();
-                return fetched;
+                return response;
               });
             }
 
-            return fetched;
+            return response;
           });
         }