File tree 1 file changed +4
-2
lines changed
plugins/image-prioritizer
1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -418,16 +418,18 @@ private function compute_sizes( OD_Tag_Visitor_Context $context ): array {
418
418
419
419
$ xpath = $ context ->processor ->get_xpath ();
420
420
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.
421
422
$ element_max_width = 0 ;
422
423
foreach ( $ group ->get_xpath_elements_map ()[ $ xpath ] ?? array () as $ element ) {
423
424
$ element_max_width = max ( $ element_max_width , $ element ->get_bounding_client_rect ()['width ' ] );
424
425
}
425
426
427
+ // Use the maximum width as the size for image in this breakpoint.
426
428
if ( $ element_max_width > 0 ) {
427
- $ size = sprintf ( '%dpx ' , $ element_max_width );
428
-
429
+ $ size = sprintf ( '%dpx ' , $ element_max_width );
429
430
$ media_feature = od_generate_media_query ( $ group ->get_minimum_viewport_width (), $ group ->get_maximum_viewport_width () );
430
431
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.
431
433
$ size = "$ media_feature $ size " ;
432
434
}
433
435
$ sizes [] = $ size ;
You can’t perform that action at this time.
0 commit comments