Closed andershagbard closed 5 years ago
I deem strict equality unnecessary. I’ve never been bitten by the lack of it.
Links starting with a hash on the same page are already prevented from being preloaded:
if (preloadLocation.hash && preloadLocation.pathname + preloadLocation.search == location.pathname + location.search) {
return
}
The check for ‘noInstant’ is at the bottom because it’s not triggered as often as the other conditions.
Links starting with a hash on the same page are already prevented from being preloaded:
I've have just tested in Chrome, but should be working in similar ways for other browsers.
If the link doesn't contain a URL, it will preload. because the pathnames will not be equal.
var preloadLocation = new URL('#top')
console.log(preloadLocation.pathname) // => blank
console.log(location.pathname) // => Current path
instant.page uses new URL(linkElement.href)
, .href
gives an absolute URL (unlike .getAttribute('href')
) even if it’s a relative URL in the HTML.
This pull request consist of 3 commits.
Use strict equality comparison
Change comparison operators to strict.
Prevent preload if href starts with hash
Prevent links like
<a href="#top">Go to top</a>
preloading.Check for 'noInstant' in dataset earlier in evaluation
Move check for
noInstant
in dataset up within theisPreloadable
function. Makes more sense, and saves from some evaluation.