Skip to content

Commit

Permalink
fix(prefetching): unobserve links once prefetched
Browse files Browse the repository at this point in the history
Fix: Unobserve links once prefetched
  • Loading branch information
addyosmani authored Dec 16, 2018
2 parents 532b985 + ce0011c commit 02778df
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ const toPrefetch = new Set();
const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const url = entry.target.href;
if (toPrefetch.has(url)) prefetcher(url);
const link = entry.target;
if (toPrefetch.has(link.href)) {
observer.unobserve(link);
prefetcher(link.href);
}
}
});
});
Expand Down

0 comments on commit 02778df

Please sign in to comment.