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

Remove requirement for both mobile and desktop URL metrics for preconnect links in Embed Optimizer #1764

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

ShyamGadde
Copy link
Contributor

Summary

Fixes #1757

Relevant technical choices

Extracted the preconnect and lazy-loading logic into separate methods.

private function get_preconnect_urls( OD_HTML_Tag_Processor $processor ): array {
/*
* The following embeds have been chosen for optimization due to their relative popularity among all embed types.
* See <https://colab.sandbox.google.com/drive/1nSpg3qoCLY-cBTV2zOUkgUCU7R7X2f_R?resourcekey=0-MgT7Ur0pT__vw-5_AHjgWQ#scrollTo=utZv59sXzXvS>.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FYI, this link doesn't seem to be publicly accessible.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, thanks for that.

@adamsilverstein Can this be exported to a Gist?

$embed_wrapper_xpath = self::get_embed_wrapper_xpath( $processor->get_xpath() );

$max_intersection_ratio = $context->url_metric_group_collection->get_element_max_intersection_ratio( $embed_wrapper_xpath );
if ( ! ( $max_intersection_ratio > 0.0 ) && embed_optimizer_update_markup( $processor, false ) && ! $this->added_lazy_script ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@westonruter Do we need to use PHP_FLOAT_EPSILON here? Wouldn't ! ( $max_intersection_ratio > 0.0 ) suffice, as that's what is used when adding preconnect links?

Copy link
Member

@westonruter westonruter Dec 20, 2024

Choose a reason for hiding this comment

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

I think ! ( $max_intersection_ratio > 0.0 ) is equivalent to 0.0 === $max_intersection_ratio (given the $max_intersection_ratio will never be negative), and both seem to work fine, but it seems in some cases even when a finite decimal is provided, it can result in a very unexpected value, for example #1765. So in this way, it seems safer to do:

Suggested change
if ( ! ( $max_intersection_ratio > 0.0 ) && embed_optimizer_update_markup( $processor, false ) && ! $this->added_lazy_script ) {
if ( $max_intersection_ratio < PHP_FLOAT_EPSILON && embed_optimizer_update_markup( $processor, false ) && ! $this->added_lazy_script ) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, thanks for clarifying. Done in 0b4150c.

*/
private function get_preconnect_urls( OD_HTML_Tag_Processor $processor ): array {
/*
* The following embeds have been chosen for optimization due to their relative popularity among all embed types.
Copy link
Member

Choose a reason for hiding this comment

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

It seems the comment lines here are missing an space before the *

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. Fixed it in 0b4150c.

@westonruter westonruter added this to the embed-optimizer n.e.x.t milestone Dec 20, 2024
@westonruter westonruter added [Type] Bug An existing feature is broken [Plugin] Embed Optimizer Issues for the Embed Optimizer plugin (formerly Auto Sizes) labels Dec 20, 2024
@ShyamGadde ShyamGadde marked this pull request as ready for review December 20, 2024 21:32
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ShyamGadde <[email protected]>
Co-authored-by: westonruter <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Embed Optimizer Issues for the Embed Optimizer plugin (formerly Auto Sizes) [Type] Bug An existing feature is broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preconnect links for embeds need not require URL Metrics to be collected from both mobile and desktop
2 participants