Bläddra i källkod

Don't preload same-page #anchor

Alexandre Dieulot 6 år sedan
förälder
incheckning
fe70998352
2 ändrade filer med 5 tillägg och 1 borttagningar
  1. 4 0
      instantpage.js
  2. 1 1
      test/app.js

+ 4 - 0
instantpage.js

@@ -47,6 +47,10 @@ function isPreloadable(linkElement) {
     return false
   }
 
+  if (urlObject.pathname + urlObject.search == location.pathname + location.search && urlObject.hash) {
+    return
+  }
+
   if ('noInstant' in linkElement.dataset) {
     return false
   }

+ 1 - 1
test/app.js

@@ -60,8 +60,8 @@ async function requestListener(req, res) {
       }
     }
 
-    content += `<a href="${req.url}#anchor" id="anchor"><span>Same-page anchor</span></a>`
     content += `<a href="/${page}?${Math.random()}#anchor"><span>Other page anchor</span></a>`
+    content += `<a href="${req.url}#anchor" id="anchor"><span>Same-page anchor</span></a>`
     content += `<a href="/${page}?${Math.random()}" data-no-instant><span>Manually blacklisted link</span></a>`
     content += `<a href="https://www.google.com/"><span>External link</span></a>`