From f93da143714bb30385b92201ca47878c5eb3abdf Mon Sep 17 00:00:00 2001 From: tdro Date: Mon, 25 Mar 2024 17:45:14 -0400 Subject: static/js/update: Fix null check Induce possible 301/307 (http -> https) on browsers that don't understand caching --- static/js/update.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'static') diff --git a/static/js/update.ts b/static/js/update.ts index 1a3384f..aa4ba77 100644 --- a/static/js/update.ts +++ b/static/js/update.ts @@ -20,14 +20,14 @@ const url = self.location.href.split("#")[0].split("?")[0]; const indicator = document.querySelector("a[data-update]"); - if (indicator.dataset.update === "refresh" || indicator === null) return; + if (indicator === null || indicator.dataset.update === "refresh") return; const anchor = indicator.cloneNode(); fetch(url, "HEAD", function (request) { const local = document.querySelector('meta[name="last-modified"]').content || document.lastModified; - const remote = request.getResponseHeader("last-modified") || document.lastModified; - const modified = Date.parse(remote) > Date.parse(local); - const drift = Date.parse(remote) - Date.parse(local); + const remote = request.getResponseHeader("last-modified") || ''; + const modified = Date.parse(remote || local) > Date.parse(local); + const drift = Date.parse(remote || local) - Date.parse(local); if (drift < 10000) return; @@ -38,14 +38,15 @@ } if (remote && modified) { - fetch(url, "GET"); - indicator.href = url; - indicator.removeAttribute("id"); - indicator.dataset.update = "refresh"; - console.log("INFO: R: " + remote); - console.log("INFO: L: " + local); - console.log("INFO: D: " + drift); - console.log("INFO: M: " + modified); + fetch(url, "GET", function () { + indicator.href = url.replace(/^https:/, "http:"); + indicator.removeAttribute("id"); + indicator.dataset.update = "refresh"; + console.log("INFO: R: " + remote); + console.log("INFO: L: " + local); + console.log("INFO: D: " + drift); + console.log("INFO: M: " + modified); + }); } }); } -- cgit v1.2.3