aboutsummaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2024-03-25 17:45:14 -0400
committertdro <tdro@noreply.example.com>2024-03-25 17:45:14 -0400
commitf93da143714bb30385b92201ca47878c5eb3abdf (patch)
tree7cdcaa1eab179c0e27b09467611f4f9a78ea39ff /static
parent00cb6ffb1c481e39810580ac2474c5fd1b4ca214 (diff)
downloadcanory-f93da143714bb30385b92201ca47878c5eb3abdf.tar.gz
canory-f93da143714bb30385b92201ca47878c5eb3abdf.tar.bz2
canory-f93da143714bb30385b92201ca47878c5eb3abdf.zip
static/js/update: Fix null check
Induce possible 301/307 (http -> https) on browsers that don't understand caching
Diffstat (limited to 'static')
-rw-r--r--static/js/update.ts25
1 files changed, 13 insertions, 12 deletions
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);
+ });
}
});
}