Skip to content

A platform for community discussion. Free, open, simple.

FIX: Only show offline page when user is offline.

Guo Xiang Tand2d3c7d24e73
diff --git a/app/assets/javascripts/service-worker.js.erb b/app/assets/javascripts/service-worker.js.erb
index 7202c6b6f08..f091e07dc25 100644
--- a/app/assets/javascripts/service-worker.js.erb
+++ b/app/assets/javascripts/service-worker.js.erb
@@ -80,7 +80,11 @@ self.addEventListener('fetch', function(event) {
// If fetch() returns a valid HTTP response with an response code in the 4xx or 5xx
// range, the catch() will NOT be called. If you need custom handling for 4xx or 5xx
// errors, see https://github.com/GoogleChrome/samples/tree/gh-pages/service-worker/fallback-response
- return caches.match(OFFLINE_URL);
+ if (!navigator.onLine) {
+ return caches.match(OFFLINE_URL);
+ } else {
+ throw error;
+ }
})
);
}