From 49ff1d32a7e3569a46e2311beedd66a6bb0520e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20=C5=A0ijanec?= Date: Mon, 30 Mar 2020 15:12:21 +0200 Subject: initial commit --- sw - Copy.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 sw - Copy.js (limited to 'sw - Copy.js') diff --git a/sw - Copy.js b/sw - Copy.js new file mode 100644 index 0000000..c1f9f91 --- /dev/null +++ b/sw - Copy.js @@ -0,0 +1,46 @@ +// Change version to cause cache refresh, sw.js SE NE SME CACHAT aka ne ga dat v assets! +const static_cache_name = "site-static-v0.0.7"; +const assets = [ + "./", + "./courbd.ttf", + "./favicon.ico", + "./favicon.png", + "./iso-8859-2.js", + "./myriadpro.otf", + "./myriadpro-semibold.otf", + "./qr.html", + "./qrcode.js", + "./qrcode.tosjis.js", + "./upn.html", + "./upn.svg", + "./index.html", + "./512x512.png", + "./192x192.png", + "./manifest.json" +]; + +self.addEventListener("install", (evt) => { + evt.waitUntil( + caches.open(static_cache_name).then((cache) => { + cache.addAll(assets); + }) + ); +}); + +// Delete old caches +self.addEventListener("activate", evt => { + evt.waitUntil( + caches.keys().then((keys) => { + return Promise.all(keys + .filter(key => key !== static_cache_name) + .map(key => caches.delete(key)) + ); + }) + ); +}); + +self.addEventListener("fetch", (evt) => { + evt.respondWith(caches.match(evt.request).then((cache_res) => { + return cache_res || fetch(evt.request); + })) +}); -- cgit v1.2.3