From 47b370df45e66fe9b3c53c9760cb8598b623482f Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Mon, 10 Dec 2018 14:36:49 -0800 Subject: [PATCH] golf: observe link & update Map in same loop; - 883 gz / 723 br --- src/index.mjs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/index.mjs b/src/index.mjs index 619de3da..a9243662 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -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}); }