浏览代码

Don't preload <a> elements without a `href` attribute

Alexandre Dieulot 6 年之前
父节点
当前提交
6b3bca1a1e
共有 2 个文件被更改,包括 5 次插入0 次删除
  1. 4 0
      instantpage.js
  2. 1 0
      test/app.js

+ 4 - 0
instantpage.js

@@ -88,6 +88,10 @@ function mouseoutListener(event) {
 }
 
 function isPreloadable(linkElement) {
+  if (!linkElement.href) {
+    return
+  }
+
   if (urlToPreload == linkElement.href) {
     return
   }

+ 1 - 0
test/app.js

@@ -77,6 +77,7 @@ 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()}" data-no-instant><span>Manually blacklisted link</span></a>`
     content += `<a href="https://www.google.com/"><span>External link</span></a>`
+    content += `<a><span>&lt;a&gt; without <code>href</code></span></a>`
 
     let footer = await fsPromises.readFile(path.resolve(__dirname, 'footer.html'))
     footer = footer.toString().replace('__HASH__', jsHash)