Skip to content

Commit

Permalink
golf: observe link & update Map in same loop;
Browse files Browse the repository at this point in the history
- 883 gz / 723 br
  • Loading branch information
lukeed committed Dec 10, 2018
1 parent 11c4369 commit 47b370d
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,15 @@ export default function (options) {
}

// If not, find all links and use IntersectionObserver.
const urls = Array.from(options.el.querySelectorAll('a'), link => {
Array.from(options.el.querySelectorAll('a'), link => {
observer.observe(link);
return link.href;
});

// Generate loader functions for each link
urls.forEach(url => {
loaderFunctions.set(url, () => {
loaderFunctions.delete(url);
prefetch(url, options.priority);
});
// Generate loader functions for each link
const uri = link.href;
loaderFunctions.set(uri, () => {
loaderFunctions.delete(uri);
prefetch(uri, options.priority);
});
});
}, {timeout: options.timeout});
}

0 comments on commit 47b370d

Please sign in to comment.