Pārlūkot izejas kodu

Remove ajax fallback placeholders and console logs

Safari re-downloads the page even when it has been preloaded with XMLHttpRequest or fetch and has cache headers. Edge would benefit from an ajax fallback but is not used enough to warrant it.
Alexandre Dieulot 6 gadi atpakaļ
vecāks
revīzija
54f01a1b20
1 mainītis faili ar 8 papildinājumiem un 20 dzēšanām
  1. 8 20
      instantpage.js

+ 8 - 20
instantpage.js

@@ -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')
 }