Skip to content
Snippets Groups Projects
Verified Commit 9c251e1a authored by Hangzhi Yu's avatar Hangzhi Yu Committed by Nik | Klampfradler
Browse files

Add serviceworker template, settings and file replacement functionality

parent 5daa73f9
No related branches found
No related tags found
1 merge request!336Resolve "Review and fix/improve PWA behaviour and serviceworker"
// 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();
}
......@@ -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"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment