Skip to content

Commit

Permalink
Relative URLs compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgiopellegrino committed Feb 14, 2025
1 parent f3f0e84 commit 767d89e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export function prefetch(url, isPriority, onlyOnMouseover) {
// ~> so that we don't repeat broken links
toPrefetch.add(str);

return prefetchOnHover((isPriority ? viaFetch : supported), str, onlyOnMouseover);
return prefetchOnHover((isPriority ? viaFetch : supported), new URL(str, location.href).toString(), onlyOnMouseover);
}),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/prefetch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const supported = hasPrefetch() ? viaDOM : viaXHR;
export function prefetchOnHover(callback, url, onlyOnMouseover, ...args) {
if (!onlyOnMouseover) return callback(url, ...args);

const elements = document.querySelectorAll(`a[href$="${decodeURIComponent(url)}"]`);
const elements = Array.from(document.querySelectorAll('a')).filter(el => el.href === url);
const timerMap = new Map();

for (const el of elements) {
Expand Down

0 comments on commit 767d89e

Please sign in to comment.