Skip to content

Conversation

verlok
Copy link
Contributor

@verlok verlok commented Dec 18, 2020

📒 This is an alternative to #213 without using data-attributes

Added the delay option, which is useful to prevent QuickLink from prefetching too much links and have a heavy impact on CDN and servers.

Type: Number
Default: 0

The amount of time each link needs to stay inside the viewport before being prefetched, in milliseconds.

Unlike throttle option which prefetches the links in order of appearance, this option makes sure the links currently inside the viewport are prefetched.

So for example, having 40 links in the page and users scrolling down fast to the 40th...

  • with throttle: 4, QuickLink prefetches the first 4 links, then the 5th, 6th, 7th ... and finally the 40th
  • with delay: 500, QuickLink prefetches only the first ones that are in viewport, then if users scroll fast enough, the 39th, the 40th, etc. because the previous 38 links didn't stay in-viewport for 500 ms

Note that the throttle and delay options can still be used together.

I hope you like and merge this PR.

Copy link
Collaborator

@addyosmani addyosmani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM with only one nit. I would recommend also adding in a docs item to https://github.com/GoogleChromeLabs/quicklink/blob/master/site/src/api.njk as part of this PR to enable it to land.

@verlok
Copy link
Contributor Author

verlok commented Jan 19, 2021

Hey @addyosmani, I guess you would release this in a new version of quicklink, e.g. 2.1.0, am I right?
That would be a minor change and that shouldn't bring breaking changes to the way quicklink works.

But for the next major version, say 3.0.0, what do you think to set the default value of the delay option to 500?
I'm saying this because, from our experiments, the optimal values are the following.

{
  delay: 500,
  threshold: 0.25
}

@addyosmani
Copy link
Collaborator

But for the next major version, say 3.0.0, what do you think to set the default value of the delay option to 500?

I would certainly be interested in us setting a better default value based on data driving config we've seen be successful in the wild :)

@addyosmani
Copy link
Collaborator

Hey @addyosmani, I guess you would release this in a new version of quicklink, e.g. 2.1.0, am I right?

Correct. We would be releasing this in a new non-major version

@addyosmani addyosmani merged commit 5cdf569 into GoogleChromeLabs:master Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants