Browse Source

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 years ago
parent
commit
54f01a1b20
1 changed files with 8 additions and 20 deletions
  1. 8 20
      instantpage.js

+ 8 - 20
instantpage.js

@@ -3,14 +3,14 @@
 let urlBeingPreloaded
 let urlBeingPreloaded
 
 
 const prefetcher = document.createElement('link')
 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'
   prefetcher.rel = 'prefetch'
   document.head.appendChild(prefetcher)
   document.head.appendChild(prefetcher)
-}
 
 
-document.addEventListener('mouseover', mouseoverListener, true)
+  document.addEventListener('mouseover', mouseoverListener, true)
+}
 
 
 function mouseoverListener(event) {
 function mouseoverListener(event) {
   const linkElement = event.target.closest('a')
   const linkElement = event.target.closest('a')
@@ -61,13 +61,7 @@ function isPreloadable(linkElement) {
 function preload(url) {
 function preload(url) {
   urlBeingPreloaded = 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() {
 function stopPreloading() {
@@ -76,13 +70,7 @@ function stopPreloading() {
   }
   }
   urlBeingPreloaded = undefined
   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')
 }
 }