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

Prevent duplicate link rel prefetches and prefetching the current page #54

Merged
merged 3 commits into from
Nov 17, 2020

Conversation

nickFalcone
Copy link
Contributor

@nickFalcone nickFalcone commented Nov 14, 2020

Add a check against the prospective href to prefetch:

Is the href equal to the current page?

…rent page.

Add two checks against the prospective href to prefetch:
1. Has the href already been prefetched?
2. Is the href equal to the current page?

There is not a benefit to duplicate prefetches or prefetching the current page.
If either check is true, return without prefetching the href.
@calibre-analytics
Copy link

Your trial has ended

Choose a plan to resume monitoring your Sites and Pull Requests. If you need help, check the Manage Your Plan and Test Usage guide.

Copy link
Collaborator

@cramforce cramforce left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! A couple comments.

src/main.js Outdated
function prefetch(e) {
if (e.target.tagName != "A") {
return;
}
if (e.target.origin != location.origin) {
return;
}
if (window.location.pathname === e.target.pathname) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would also need to compare the query string. So, all of the URL except for the fragment.

src/main.js Outdated
if (window.location.pathname === e.target.pathname) {
return;
}
if (prefetched.includes(e.target.href)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove. The way the prefetch cache works is that it will cache the returning resource for 5 minutes independent of its caching headers and duplicate fetches should not happen. If this is not the case, please provide a DevTools screenshot showing it and ideally file a crbug.com

@nickFalcone
Copy link
Contributor Author

Thanks for your feedback!

I removed the check for duplicate prefetch and updated the comparison to include query string (excluding the URL fragment).

Copy link
Collaborator

@cramforce cramforce left a comment

Choose a reason for hiding this comment

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

Thanks!

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