diff options
author | Anton Luka Šijanec <sijanecantonluka@gmail.com> | 2020-02-08 21:45:13 +0100 |
---|---|---|
committer | Anton Luka Šijanec <sijanecantonluka@gmail.com> | 2020-02-08 21:45:13 +0100 |
commit | f6069173c53ff0f9f05a416f9849d94e9c5bbebf (patch) | |
tree | 20c2bb1d1bd24d3a7f07d6e62a72d3f3171d5d0c | |
parent | added icons to side menu (diff) | |
download | beziapp-f6069173c53ff0f9f05a416f9849d94e9c5bbebf.tar beziapp-f6069173c53ff0f9f05a416f9849d94e9c5bbebf.tar.gz beziapp-f6069173c53ff0f9f05a416f9849d94e9c5bbebf.tar.bz2 beziapp-f6069173c53ff0f9f05a416f9849d94e9c5bbebf.tar.lz beziapp-f6069173c53ff0f9f05a416f9849d94e9c5bbebf.tar.xz beziapp-f6069173c53ff0f9f05a416f9849d94e9c5bbebf.tar.zst beziapp-f6069173c53ff0f9f05a416f9849d94e9c5bbebf.zip |
-rw-r--r-- | sw.js | 28 |
1 files changed, 26 insertions, 2 deletions
@@ -1,6 +1,7 @@ // Change version to cause cache refresh const static_cache_name = "site-static-v1.0.8"; -// Got them with find . -not -path '*/\.*' | sed "s/.*/\"&\",/" +// Got them with find . -not -path '*/\.*' | sed "s/.*/\"&\",/" | grep -v sw.js +// sw.js NE SME BITI CACHAN, ker vsebuje verzijo! const assets = [ ".", "./login.html", @@ -28,7 +29,6 @@ const assets = [ "./fonts/fa-brands-400.eot", "./fonts/materialicons.woff2", "./index.html", -"./sw.js", "./img", "./img/avatars", "./img/avatars/asijanec.png", @@ -148,6 +148,30 @@ self.addEventListener("activate", evt => { ); }); +self.addEventListener('message', event => { + if (event.data) { + let data = JSON.parse(event.data); // parse the message back to JSON + if (data.action == "addtocache") { // check the action + event.waitUntil( + caches.open(static_cache_name).then(function(cache) { + try { + return cache.add([data.url]); + } + catch(error) { + console.error("[sw.js] error: "+error); + } + }) + ); + } else if (data.action == "deletecaches") { + caches.keys().then(function(names) { + for (let name of names) + console.log("[sw.js] deleting cache named "+name); + caches.delete(name); + }); + } + } +}); + self.addEventListener("fetch", (evt) => { evt.respondWith(caches.match(evt.request).then((cache_res) => { return cache_res || fetch(evt.request); |