[FEAT] Enable PWA functionality

This commit is contained in:
2023-01-20 17:46:21 +00:00
parent 0d03678674
commit e15de01cfa
8 changed files with 82 additions and 4 deletions

View 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);
})
);
});