GoogleChromeLabs / quicklink

⚡️Faster subsequent page-loads by prefetching in-viewport links during idle time
https://getquick.link
Apache License 2.0
11.03k stars 404 forks source link

Allow adding elements directly to the Intersection Observer #54

Open lfre opened 5 years ago

lfre commented 5 years ago

Per the discussion here: https://github.com/GoogleChromeLabs/quicklink/issues/43.

For dynamic content, depending on the page structure the query options.el.querySelector('a'), could return links that were already observed/prefetched and now unobserved (thanks to https://github.com/GoogleChromeLabs/quicklink/pull/51).

I provided a couple of options here: https://github.com/GoogleChromeLabs/quicklink/issues/43#issuecomment-447595607

xtreomass12 commented 5 years ago

Now it's working

renosbest commented 5 years ago

@renosbest _

mherchel commented 5 years ago

I'm the maintainer of the Drupal module that integrates quicklink into the CMS. This would really help users of traditional server-rendered CMS' by allowing other components (modules) to tell Quicklink to prefetch their own URLs. So ++

demianrenzulli commented 4 years ago

As mentioned before, every intersected link is unobserved to avoid multiple prefetched on it.

lfre commented 4 years ago

@demianrenzulli This is different than #43. The point here is that dynamic elements added to the same container would increase the querySelectorAll call unnecessarily. This can be avoided by allowing an override of the whole querySelectorAll call. e.g:

const elements = options.links || (options.el || document).querySelectorAll('a');

Additionally, the current check could be improved by moving the toPrefetch.has earlier to avoid re-observing here.

Hope that helps to distinguish the 2 issues.

demianrenzulli commented 4 years ago

Thanks for confirming this @lfre, and sorry for the confusion!

It seems like it makes sense to keep this open then, so it can be considered as an FR for a future version.