about summary refs log tree commit diff
path: root/app/javascript
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>2018-05-16 03:14:30 +0900
committerEugen Rochko <eugen@zeonfederated.com>2018-05-15 20:14:30 +0200
commit918cfd3be600b50d7e1a034f8b1e953eb748e641 (patch)
tree504b13b7d2bb6490ac8a9f1b9b08bcb157a7e04c /app/javascript
parentff84c18e3de8be9ee491c55453993281c277a5a6 (diff)
Ignore only-if-cached cache mode on Mozilla Firefox prior to version 60 (#7503)
Diffstat (limited to 'app/javascript')
-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;
           });
         }