diff options
author | BuildTools <unconfigured@null.spigotmc.org> | 2020-09-04 16:47:25 +0200 |
---|---|---|
committer | BuildTools <unconfigured@null.spigotmc.org> | 2020-09-04 16:47:25 +0200 |
commit | d4edddb325d98d637fdda47b92a4e90fe03c911e (patch) | |
tree | 305e365c2eda23f36d671f1c29511cb58861ae2f | |
parent | upstream so spremenili manifest.webmanifest v manifest.json (diff) | |
download | ttx-app-d4edddb325d98d637fdda47b92a4e90fe03c911e.tar ttx-app-d4edddb325d98d637fdda47b92a4e90fe03c911e.tar.gz ttx-app-d4edddb325d98d637fdda47b92a4e90fe03c911e.tar.bz2 ttx-app-d4edddb325d98d637fdda47b92a4e90fe03c911e.tar.lz ttx-app-d4edddb325d98d637fdda47b92a4e90fe03c911e.tar.xz ttx-app-d4edddb325d98d637fdda47b92a4e90fe03c911e.tar.zst ttx-app-d4edddb325d98d637fdda47b92a4e90fe03c911e.zip |
-rw-r--r-- | index.html | 2 | ||||
-rw-r--r-- | sw.js | 43 |
2 files changed, 38 insertions, 7 deletions
@@ -17,6 +17,8 @@ <script> if (window.location.search == "?help") { window.location.href = "/900/1"; + } else if (window.location.search == "?404") { + window.location.href = "/900/404/index.html"; } else { window.location.href = "/100/1"; } @@ -1,8 +1,11 @@ // 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.4"; +const static_cache_name = "site-static-v0.0.5"; const offlineUrl = "/offline.html"; const assets = [ "/manifest.json", // proxy | + "/900/404/", // moje | + "/900/404/index.html", // moje | + "/900/404", // moje | "/", // proxy | proxyjan je tudi sw.js "/index.html", // proxy | "/slike/icons-512.png", // proxy | redfox.js je poklican iz @@ -22,7 +25,6 @@ const assets = [ "/favicon.png", // proxy | "/offline.html" // moje | ]; - self.addEventListener("install", (evt) => { evt.waitUntil( caches.open(static_cache_name).then((cache) => { @@ -48,13 +50,40 @@ self.addEventListener("fetch", (event) => { ( (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 caches.match(offlineUrl); + + event.respondWith(caches.match(event.request) + .then((cache_res) => { + if (cache_res) { + return cache_res; + } else { + +///// start of fetch thingies ///// + + return fetch(event.request.url) + .then(response => { + response.redirected = false; + console.log(response); + if (response.redirected) { +return new Response("<meta http-equiv=refresh content=0;/?404 />", { + status: 200, + statusText: "OK", + headers: response.headers +}); + } + return response; + }) + .catch(error => { + return caches.match(offlineUrl); + }); + +///// end of fetch thingys ///// + + } })); } else { // zahteva je za nek resource (css/js/img), ne za stran - event.respondWith(caches.match(event.request).then((cache_res) => { + event.respondWith(caches.match(event.request) + .then((cache_res) => { return cache_res || fetch(event.request); - })) + })); } }); |