diff options
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); + }); } }); })(); |