aboutsummaryrefslogtreecommitdiff
path: root/assets
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2024-03-16 15:22:06 -0400
committertdro <tdro@noreply.example.com>2024-03-16 15:22:06 -0400
commitaf5c542b3ff6cbbdeec6da1b1a03e58b007fd941 (patch)
treed700e5502847c82996fb21a9065d9eb91acb61ba /assets
parentd1ef2e9cda26ec517b59e7e410f223b043029127 (diff)
downloadcanory-af5c542b3ff6cbbdeec6da1b1a03e58b007fd941.tar.gz
canory-af5c542b3ff6cbbdeec6da1b1a03e58b007fd941.tar.bz2
canory-af5c542b3ff6cbbdeec6da1b1a03e58b007fd941.zip
static/js/instantpage: Add custom prefetch
Diffstat (limited to 'assets')
-rw-r--r--assets/js/index.js23
1 files changed, 18 insertions, 5 deletions
diff --git a/assets/js/index.js b/assets/js/index.js
index e0e0436..f6c1686 100644
--- a/assets/js/index.js
+++ b/assets/js/index.js
@@ -165,9 +165,18 @@
}
})();
(function() {
+ function fetch(url, method, callback) {
+ const http = new XMLHttpRequest();
+ http.onreadystatechange = function() {
+ if (http.readyState === 4 && http.status === 200) {
+ if (callback) callback(http);
+ }
+ };
+ http.open(method, url);
+ http.send();
+ return http;
+ }
self.addEventListener("DOMContentLoaded", function() {
- let mouseoverTimer;
- let lastTouchTimestamp;
const prefetches = new Set();
const prefetchElement = document.createElement("link");
const isSupported = prefetchElement.relList && prefetchElement.relList.supports && prefetchElement.relList.supports("prefetch") && window.IntersectionObserver && "isIntersecting" in IntersectionObserverEntry.prototype;
@@ -175,6 +184,8 @@
const allowExternalLinks = "instantAllowExternalLinks" in document.body.dataset;
const useWhitelist = "instantWhitelist" in document.body.dataset;
const mousedownShortcut = "instantMousedownShortcut" in document.body.dataset;
+ let mouseoverTimer;
+ let lastTouchTimestamp;
let delayOnHover = 65;
let useMousedown = false;
let useMousedownOnly = false;
@@ -354,10 +365,12 @@
return;
}
const prefetcher = document.createElement("link");
- prefetcher.rel = "prefetch";
+ prefetcher.rel = "custom-prefetch";
prefetcher.href = url;
- document.head.appendChild(prefetcher);
- prefetches.add(url);
+ fetch(url, "GET", function() {
+ document.head.appendChild(prefetcher);
+ prefetches.add(url);
+ });
}
});
})();