mirror of
https://github.com/Southampton-RSG/breccia-mapper.git
synced 2026-03-03 11:27:09 +00:00
[FEAT] Re-enable basic PWA support without customisation options
This commit is contained in:
@@ -1,24 +1,61 @@
|
||||
var staticCacheName = "djangopwa-v1";
|
||||
var staticCacheName = "django-pwa-v" + new Date().getTime();
|
||||
var filesToCache = [
|
||||
'/offline',
|
||||
'/css/django-pwa-app.css',
|
||||
'/media/icon-72x72.png',
|
||||
'/media/icon-96x96.png',
|
||||
'/media/icon-128x128.png',
|
||||
'/media/icon-144x144.png',
|
||||
'/media/icon-152x152.png',
|
||||
'/media/icon-192x192.png',
|
||||
'/media/icon-384x384.png',
|
||||
'/media/icon-512x512.png',
|
||||
'/static/media/splash-640x1136.png',
|
||||
'/static/media/splash-750x1334.png',
|
||||
'/static/media/splash-1242x2208.png',
|
||||
'/static/media/splash-1125x2436.png',
|
||||
'/static/media/splash-828x1792.png',
|
||||
'/static/media/splash-1242x2688.png',
|
||||
'/static/media/splash-1536x2048.png',
|
||||
'/static/media/splash-1668x2224.png',
|
||||
'/static/media/splash-1668x2388.png',
|
||||
'/static/media/splash-2048x2732.png'
|
||||
];
|
||||
|
||||
self.addEventListener("install", function (event) {
|
||||
event.waitUntil(
|
||||
caches.open(staticCacheName).then(function (cache) {
|
||||
return cache.addAll([""]);
|
||||
})
|
||||
);
|
||||
// Cache on install
|
||||
self.addEventListener("install", event => {
|
||||
this.skipWaiting();
|
||||
event.waitUntil(
|
||||
caches.open(staticCacheName)
|
||||
.then(cache => {
|
||||
return cache.addAll(filesToCache);
|
||||
})
|
||||
)
|
||||
});
|
||||
|
||||
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);
|
||||
})
|
||||
);
|
||||
// Clear cache on activate
|
||||
self.addEventListener('activate', event => {
|
||||
event.waitUntil(
|
||||
caches.keys().then(cacheNames => {
|
||||
return Promise.all(
|
||||
cacheNames
|
||||
.filter(cacheName => (cacheName.startsWith("django-pwa-")))
|
||||
.filter(cacheName => (cacheName !== staticCacheName))
|
||||
.map(cacheName => caches.delete(cacheName))
|
||||
);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// Serve from Cache
|
||||
self.addEventListener("fetch", event => {
|
||||
event.respondWith(
|
||||
caches.match(event.request)
|
||||
.then(response => {
|
||||
return response || fetch(event.request);
|
||||
})
|
||||
.catch(() => {
|
||||
return caches.match('offline');
|
||||
})
|
||||
)
|
||||
});
|
||||
Reference in New Issue
Block a user