FEATURE: special offline support restricted to Android only

The special offline page with fetch interception in service worker
is only strongly required on Android ad a pre-req for PWAs

This is now strongly restricted only to Android while iOS PWA support
gets better

Long term if we build offline support we can unlock it more globally
This commit is contained in:
Sam
2018-10-29 16:29:19 +11:00
parent 5c86e2d749
commit f8305f53c7

View File

@ -1,5 +1,13 @@
'use strict'; 'use strict';
// Special offline and fetch interception is restricted to Android only
// we have had a large amount of pain supporting this on Firefox / Safari
// it is only strongly required on Android, when PWA gets better on iOS
// we can unlock it there as well, for Desktop we can consider unlocking it
// if we start supporting offline browsing for laptops
if (/(android)/i.test(navigator.userAgent)) {
// Incrementing CACHE_VERSION will kick off the install event and force previously cached // Incrementing CACHE_VERSION will kick off the install event and force previously cached
// resources to be cached again. // resources to be cached again.
const CACHE_VERSION = 1; const CACHE_VERSION = 1;
@ -10,7 +18,7 @@ const CURRENT_CACHES = {
const OFFLINE_URL = 'offline.html'; const OFFLINE_URL = 'offline.html';
function createCacheBustedRequest(url) { const createCacheBustedRequest = function(url) {
var headers = new Headers({ var headers = new Headers({
'Discourse-Track-View': '0' 'Discourse-Track-View': '0'
}); });
@ -103,6 +111,7 @@ self.addEventListener('fetch', function(event) {
// handled by the browser as if there were no service worker involvement. // handled by the browser as if there were no service worker involvement.
}); });
}
const idleThresholdTime = 1000 * 10; // 10 seconds const idleThresholdTime = 1000 * 10; // 10 seconds
var lastAction = -1; var lastAction = -1;