-
Notifications
You must be signed in to change notification settings - Fork 101
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
Choose smaller poster image size based on actual dimensions #1595
Conversation
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this!! A few suggestions.
plugins/image-prioritizer/class-image-prioritizer-video-tag-visitor.php
Outdated
Show resolved
Hide resolved
plugins/image-prioritizer/class-image-prioritizer-video-tag-visitor.php
Outdated
Show resolved
Hide resolved
plugins/image-prioritizer/class-image-prioritizer-video-tag-visitor.php
Outdated
Show resolved
Hide resolved
$poster_id = attachment_url_to_postid( $poster ); | ||
|
||
if ( $poster_id > 0 && $max_element_width > 0 ) { | ||
$smaller_image_url = wp_get_attachment_image_url( $poster_id, array( (int) $max_element_width, 0 ) ); | ||
$processor->set_attribute( 'poster', $smaller_image_url ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One possible consideration to make here is that if there are no URL Metrics gathered for the largest breakpoint group that in this case the poster should not be reduced in size. The reason being is that if there are only mobile visitors from whom URL Metrics have been gathered, as soon as a desktop visitor visits they could see a poster that is much lower-resolution than it should be.
Maybe this is an edge case that we shouldn't worry about right now, but it's something to keep in mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point, I think this is relevant to consider. I'd say we should be cautious in such a case and prioritize a "not broken" experience over better performance. Basically, unless we have data for all three viewports, we cannot reasonably make a decision to optimize.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to this is https://github.com/WordPress/performance/pull/1596/files#r1803569058 where I realize that lazy-loading may currently be incorrectly applied to an element on desktop if it is not visible on mobile and only URL Metrics for mobile have been collected. But if a site only ever gets mobile traffic, should the lack of desktop data be a blocker?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a low-res poster image on desktop if there's a lack of desktop traffic is acceptable.
But we can be more strict for now and then see how well it works. So how can I easily check whether values exist for every viewport? :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The OD_URL_Metric_Group_Collection::is_every_group_populated()
method will indicate whether all groups have at least one URL Metric. But for some sites all viewports may never get populated, such as if no tablet visitors show up. See #1404.
So should this only check if the largest group (desktop) is populated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In reality, the last item in iterator_to_array( $context->url_metric_group_collection )
will have the widest viewport since OD_URL_Metric_Group_Collection
sorts the breakpoints before constructing the groups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably make sense to add a helper to OD_URL_Metric_Group_Collection
which returns the widest group (i.e. desktop). But we can do that later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I can give that a try tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't want to lead you astray, so I went ahead and tested it out in 3521f9e. It seems to work! There are two test cases, one for when desktop URL metrics are collected and another when they are absent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing, thanks a lot!
plugins/image-prioritizer/class-image-prioritizer-video-tag-visitor.php
Outdated
Show resolved
Hide resolved
plugins/image-prioritizer/class-image-prioritizer-video-tag-visitor.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@swissspidy Looks great to me, other than what @westonruter already outlined.
Co-authored-by: Weston Ruter <westonruter@google.com>
plugins/image-prioritizer/class-image-prioritizer-video-tag-visitor.php
Outdated
Show resolved
Hide resolved
plugins/image-prioritizer/class-image-prioritizer-video-tag-visitor.php
Outdated
Show resolved
Hide resolved
plugins/image-prioritizer/class-image-prioritizer-video-tag-visitor.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple minor suggestions left. So I'm pre-approving!
Co-authored-by: Weston Ruter <westonruter@google.com>
Summary
Fixes #1575
On my test post with 7 large videos, the videos were displayed ~610px wide on desktop. With this PR, the full image URLs (which were 1920px wide) are replaced with 767px wide versions.
Image file sizes before this PR: 738 KB
After: 175 KB (!)
Relevant technical choices