diff --git a/aleksis/core/static/js/serviceworker.js b/aleksis/core/static/js/serviceworker.js index 93d9797c78db9756cba6f1f6caa46fc8c14ae57b..c260c9ef2b07a40143b2121f1e5f2f104636bc6b 100644 --- a/aleksis/core/static/js/serviceworker.js +++ b/aleksis/core/static/js/serviceworker.js @@ -1,18 +1,9 @@ -// This is the AlekSIS service worker - -const CACHE = "aleksis-cache"; -const precacheFiles = [ - '', -]; +// This is the AlekSIS service worker -const offlineFallbackPage = '/offline'; +const CACHE = 'aleksis-cache'; -const avoidCachingPaths = [ - '/admin', - '/settings', - '/accounts/login' -]; // TODO: More paths are needed +const offlineFallbackPage = 'offline/'; function pathComparer(requestUrl, pathRegEx) { return requestUrl.match(new RegExp(pathRegEx)); @@ -40,10 +31,7 @@ self.addEventListener("install", function (event) { event.waitUntil( caches.open(CACHE).then(function (cache) { console.log("[AlekSIS PWA] Caching pages during install."); - - return cache.addAll(precacheFiles).then(function () { - return cache.add(offlineFallbackPage); - }); + return cache.addAll(precachePaths); }) ); }); @@ -95,11 +83,11 @@ function fromCache(event) { } function updateCache(request, response) { - if (!comparePaths(request.url, avoidCachingPaths)) { + if (response.headers.get('cache-control') && response.headers.get('cache-control').includes('no-cache')) { + return Promise.resolve(); + } else { return caches.open(CACHE).then(function (cache) { return cache.put(request, response); }); } - - return Promise.resolve(); } diff --git a/aleksis/core/urls.py b/aleksis/core/urls.py index 7b5b06632114b25cf030d7a5942e69733c55d20a..6c989ddf7cac9fab6f99e8b309905f45a4aeebde 100644 --- a/aleksis/core/urls.py +++ b/aleksis/core/urls.py @@ -18,6 +18,7 @@ from .util.core_helpers import is_celery_enabled urlpatterns = [ path("", include("django_prometheus.urls")), path("", include("pwa.urls"), name="pwa"), + path("offline/", views.offline, name="offline"), path("about/", views.about, name="about_aleksis"), path("admin/", admin.site.urls), path("data_management/", views.data_management, name="data_management"),