Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added threshold option to reduce impact on CDNs and servers #214

Merged
merged 2 commits into from Jun 18, 2021

Conversation

verlok
Copy link
Contributor

@verlok verlok commented Dec 16, 2020

Added threshold option to allow users select the % of link areas that entered the viewport before prefetching, reduce the number of links to prefetch at a time, and ultimately reduce the impact on CDNs and servers.

Type: Number
Default: 0

The area percentage of each link that must have entered the viewport to be fetched, in its decimal form (e.g. 0.25 = 25%).

So for example, having 4 links in the page, 2 of which completely in-viewport and other 2 that are barely in-viewport (for less than 25% of their area), setting threshold: 0.25 QuickLink will prefetch only the first and the second link, which are fully in-viewport. Then it will prefetch the 3rd and the 4th link when users scroll down for > 25% of the next link areas.

I hope you like and merge this PR.

…at entered the viewport before prefetching
@verlok verlok changed the title Added threshold option Added threshold option to reduce impact on CDNs and servers Dec 16, 2020
@verlok
Copy link
Contributor Author

verlok commented Jun 15, 2021

Hey @addyosmani, how about this PR?
We are already using this option in a custom version of Quicklink but we'd like to see it in the official repo :)

@verlok
Copy link
Contributor Author

verlok commented Jun 16, 2021

Hey @addyosmani, me again.

I created a small demo to find the most effective quicklink settings.

It's here:
https://www.andreaverlicchi.eu/quicklink-optimal-options/

Changing the values in the demo I realized that we can very well set the threshold to 0.9.

Long story short, ideal settings in my opinion are:

{
   throttle: 4,
   threshold: 0.9,
   delay: 500
}

Which for us means that in order to fetch a PDP, its link must be in viewport for 90% of its extension, stay in this condition for 500ms, and no more than 4 other prefetches must be running.

I hope this convince you to merge this PR!
After all, it's a single line of code: passing the threshold option to the IntersectionObserver options.

@addyosmani
Copy link
Collaborator

Hey @verlok. If we can resolve the merge conflicts this should be good to merge!

@verlok
Copy link
Contributor Author

verlok commented Jun 18, 2021

Sure thing @addyosmani. I've just done that.

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.

LGTM. Thanks for this contribution!

@addyosmani addyosmani merged commit d3746e1 into GoogleChromeLabs:master Jun 18, 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.

None yet

2 participants