Skip to content

Commit 47b370d

Browse files
committed
golf: observe link & update Map in same loop;
- 883 gz / 723 br
1 parent 11c4369 commit 47b370d

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

src/index.mjs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,15 @@ export default function (options) {
5959
}
6060

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

67-
// Generate loader functions for each link
68-
urls.forEach(url => {
69-
loaderFunctions.set(url, () => {
70-
loaderFunctions.delete(url);
71-
prefetch(url, options.priority);
72-
});
65+
// Generate loader functions for each link
66+
const uri = link.href;
67+
loaderFunctions.set(uri, () => {
68+
loaderFunctions.delete(uri);
69+
prefetch(uri, options.priority);
70+
});
7371
});
7472
}, {timeout: options.timeout});
7573
}

0 commit comments

Comments
 (0)