diff options
author | tdro <tdro@noreply.example.com> | 2024-03-16 15:22:06 -0400 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2024-03-16 15:22:06 -0400 |
commit | af5c542b3ff6cbbdeec6da1b1a03e58b007fd941 (patch) | |
tree | d700e5502847c82996fb21a9065d9eb91acb61ba /assets | |
parent | d1ef2e9cda26ec517b59e7e410f223b043029127 (diff) | |
download | canory-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.js | 23 |
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); + }); } }); })(); |