-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normalize URLs before checking the toPrefetch
set
#28
Comments
toPrefetch
set
This is a great catch. Nice work highlighting the normalization issue, @mathiasbynens ❤️ Given URL() has pretty decent cross-browser support, I'm happy for us to use your suggested change in some form. We probably want to sanity check if normalization should happen elsewhere in index.mjs. Do you want to PR a fix? If not, happy to patch directly :) |
Nothing gets added to That said, we should still probably normalize so that the IMO, normalization should happen here: https://github.com/GoogleChromeLabs/quicklink/blob/master/src/index.mjs#L37 It'll be redundant for the "scraped" links, but it avoids adding a new function 😇 |
@lukeed Hah. Avoiding the addition of a new function is fair. Were you thinking of normalization around L37 looking similar to this? function prefetcher(url) {
const nURL = new URL(url).toString();
toPrefetch.delete(nURL);
prefetch(nURL, observer.priority);
} |
I blame Jason 🙃 Was thinking this: function prefetcher(url) {
toPrefetch.delete(url);
prefetch(new URL(url).toString(), observer.priority);
} Since anything that makes its way into Edit: We can also just do |
Closed by #37. Thanks again! |
For example, these three URLs are all equivalent:
(That last one is an extreme example, but it’s pretty common to see the first and second variation used interchangeably.)
When reading an element’s
.href
like inquicklink/src/index.mjs
Line 25 in f9a2ca7
However, the same normalization is not applied when the user manually passes in URLs:
quicklink/src/index.mjs
Line 67 in f9a2ca7
Because of this, the
toPrefetch
set currently ends up with three separate entries in this case, even though all of them normalize to the same URL:It can be solved by forcing URL normalization before calling
prefetcher
on this line:quicklink/src/index.mjs
Line 67 in f9a2ca7
The text was updated successfully, but these errors were encountered: