|
@@ -3,14 +3,14 @@
|
|
|
let urlBeingPreloaded
|
|
|
|
|
|
const prefetcher = document.createElement('link')
|
|
|
-const useAjaxFallback = !(prefetcher.relList && prefetcher.relList.supports && prefetcher.relList.supports('prefetch'))
|
|
|
+const isSupported = prefetcher.relList && prefetcher.relList.supports && prefetcher.relList.supports('prefetch')
|
|
|
|
|
|
-if (!useAjaxFallback) {
|
|
|
+if (isSupported) {
|
|
|
prefetcher.rel = 'prefetch'
|
|
|
document.head.appendChild(prefetcher)
|
|
|
-}
|
|
|
|
|
|
-document.addEventListener('mouseover', mouseoverListener, true)
|
|
|
+ document.addEventListener('mouseover', mouseoverListener, true)
|
|
|
+}
|
|
|
|
|
|
function mouseoverListener(event) {
|
|
|
const linkElement = event.target.closest('a')
|
|
@@ -61,13 +61,7 @@ function isPreloadable(linkElement) {
|
|
|
function preload(url) {
|
|
|
urlBeingPreloaded = url
|
|
|
|
|
|
- if (!useAjaxFallback) {
|
|
|
- prefetcher.href = url
|
|
|
- console.log(`Preloading ${url}`)
|
|
|
- }
|
|
|
- else {
|
|
|
- console.log(`Todo: preload with Ajax ${url}`)
|
|
|
- }
|
|
|
+ prefetcher.href = url
|
|
|
}
|
|
|
|
|
|
function stopPreloading() {
|
|
@@ -76,13 +70,7 @@ function stopPreloading() {
|
|
|
}
|
|
|
urlBeingPreloaded = undefined
|
|
|
|
|
|
- if (!useAjaxFallback) {
|
|
|
- /* The spec says an empty string should abort the prefetching
|
|
|
- * but Firefox 64 interprets it as a relative URL to prefetch. */
|
|
|
- prefetcher.removeAttribute('href')
|
|
|
- console.log(`Stopped preloading`)
|
|
|
- }
|
|
|
- else {
|
|
|
- console.log(`Todo: stop preloading with xhr.abort()`)
|
|
|
- }
|
|
|
+ /* The spec says an empty string should abort the prefetching
|
|
|
+ * but Firefox 64 interprets it as a relative URL to prefetch. */
|
|
|
+ prefetcher.removeAttribute('href')
|
|
|
}
|