mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 03:17:07 +00:00
[FEAT] Enable PWA functionality
This commit is contained in:
24
breccia_mapper/static/js/serviceworker.js
Normal file
24
breccia_mapper/static/js/serviceworker.js
Normal file
@@ -0,0 +1,24 @@
|
||||
var staticCacheName = "djangopwa-v1";
|
||||
|
||||
self.addEventListener("install", function (event) {
|
||||
event.waitUntil(
|
||||
caches.open(staticCacheName).then(function (cache) {
|
||||
return cache.addAll([""]);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", function (event) {
|
||||
var requestUrl = new URL(event.request.url);
|
||||
if (requestUrl.origin === location.origin) {
|
||||
if (requestUrl.pathname === "/") {
|
||||
event.respondWith(caches.match(""));
|
||||
return;
|
||||
}
|
||||
}
|
||||
event.respondWith(
|
||||
caches.match(event.request).then(function (response) {
|
||||
return response || fetch(event.request);
|
||||
})
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user