Skip to content

Commit 6045b18

Browse files
committed
Add clarifying comments
1 parent cdda7c3 commit 6045b18

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

plugins/image-prioritizer/class-image-prioritizer-img-tag-visitor.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -418,16 +418,18 @@ private function compute_sizes( OD_Tag_Visitor_Context $context ): array {
418418

419419
$xpath = $context->processor->get_xpath();
420420
foreach ( $context->url_metric_group_collection as $group ) {
421+
// Obtain the maximum width that the image appears among all URL Metrics collected for this viewport group.
421422
$element_max_width = 0;
422423
foreach ( $group->get_xpath_elements_map()[ $xpath ] ?? array() as $element ) {
423424
$element_max_width = max( $element_max_width, $element->get_bounding_client_rect()['width'] );
424425
}
425426

427+
// Use the maximum width as the size for image in this breakpoint.
426428
if ( $element_max_width > 0 ) {
427-
$size = sprintf( '%dpx', $element_max_width );
428-
429+
$size = sprintf( '%dpx', $element_max_width );
429430
$media_feature = od_generate_media_query( $group->get_minimum_viewport_width(), $group->get_maximum_viewport_width() );
430431
if ( null !== $media_feature ) {
432+
// Note: The null case only happens when a site has filtered od_breakpoint_max_widths to be an empty array, meaning there is only one viewport group.
431433
$size = "$media_feature $size";
432434
}
433435
$sizes[] = $size;

0 commit comments

Comments
 (0)