Skip to content

Commit

Permalink
fix: stop observing links once prefetched;
Browse files Browse the repository at this point in the history
- saved reference to link, not url, for better gzip
- 787 gz / 654 br
  • Loading branch information
lukeed committed Dec 16, 2018
1 parent 532b985 commit ce0011c
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 ce0011c

Please sign in to comment.