diff --git a/service-worker.js b/service-worker.js new file mode 100644 index 0000000..d0424a8 --- /dev/null +++ b/service-worker.js @@ -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); + }) + ); +}); \ No newline at end of file