summaryrefslogtreecommitdiffstats
path: root/sw.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sw.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/sw.js b/sw.js
new file mode 100644
index 0000000..756f11f
--- /dev/null
+++ b/sw.js
@@ -0,0 +1,59 @@
+// 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.0";
+const offlineUrl = "/offline.html";
+const assets = [
+ "/", // proxy | proxyjan je tudi sw.js
+ "/index.html", // proxy |
+ "/512.png", // moje | redfox.js je poklican iz
+ "/512.png", // proxy | vsake proxyjane html strani
+ "/manifest.json", // moje | in vsebuje custom skripte,
+ "/desktop2.css", // proxy | kot na primer sw inštalacijo.
+ "/phone2.css", // proxy |
+ "/pin.svg", // proxy |
+ "/redfox.js", // moje |
+ "/slike/home100.svg", // proxy |
+ "/slike/prPage.svg", // proxy |
+ "/slike/prSubPage.svg", // proxy |
+ "/slike/neSubPage.svg", // proxy |
+ "/slike/nePage.svg", // proxy |
+ "/slike/keyboard.svg", // proxy |
+ "/slike/go.svg", // proxy |
+ "/favicon.png", // proxy |
+ "/offline.html" // moje |
+];
+
+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) => {
+ if (event.request.mode === 'navigate' || // tole ni povsod podprto, zato
+ ( (event.request.method === 'GET' || // če je GET
+ event.request.method === 'POST') // ali POST zahteva
+ && event.request.headers.get('accept').includes('text/html'))) {
+
+ event.respondWith(fetch(event.request.url).catch(error => {
+ return cacches.match(offlineUrl);
+ }));
+ } else { // zahteva je za nek resource (css/js/img), ne za stran
+ evt.respondWith(caches.match(evt.request).then((cache_res) => {
+ return cache_res || fetch(evt.request);
+ }))
+ }
+});