Add service-worker.js
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
const CACHE_NAME = "woordjes-v1";
|
||||||
|
|
||||||
|
const FILES = [
|
||||||
|
"/learn.php",
|
||||||
|
"/assets/css/style.css",
|
||||||
|
"/assets/js/app.js"
|
||||||
|
];
|
||||||
|
|
||||||
|
self.addEventListener("install", (event) => {
|
||||||
|
event.waitUntil(
|
||||||
|
caches.open(CACHE_NAME).then((cache) => {
|
||||||
|
return cache.addAll(FILES);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
self.addEventListener("fetch", (event) => {
|
||||||
|
|
||||||
|
const url = event.request.url;
|
||||||
|
|
||||||
|
// API NIET cachen (anders breekt je SRS)
|
||||||
|
if (url.includes("/api/")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.respondWith(
|
||||||
|
caches.match(event.request).then((cached) => {
|
||||||
|
return cached || fetch(event.request);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user