[wp-trac] [WordPress Trac] #58635: Images before main query loop are not counted towards lazy-loading threshold

WordPress Trac noreply at wordpress.org
Mon Jun 26 18:14:41 UTC 2023


#58635: Images before main query loop are not counted towards lazy-loading
threshold
--------------------------+------------------------------------------
 Reporter:  flixos90      |      Owner:  flixos90
     Type:  defect (bug)  |     Status:  assigned
 Priority:  normal        |  Milestone:  6.3
Component:  Media         |    Version:  trunk
 Severity:  normal        |   Keywords:  needs-patch needs-unit-tests
  Focuses:  performance   |
--------------------------+------------------------------------------
 #56930 (for block themes) and #58211 (for classic themes) added logic to
 also omit images before the main query loop from being lazy-loaded. While
 all of those images are now correctly omitting the `loading="lazy"`
 attribute, an issue introduced by that is that those images do not count
 towards the lazy-loading threshold (see `wp_omit_loading_attr_threshold()`
 function). This leads to a potentially excessive number of images to be
 lazy-loaded, for example even if the header already includes a few large
 enough images, WordPress core will only start counting images within the
 main query loop and thus omit `loading="lazy"` on the first x images (3 as
 of #58213) ''among those'', which is pointless if the header already
 contained enough large images to cover all images within the viewport.

 This ticket is about fixing that so that images with a certain minimum
 size in the header of the page are also counted towards the threshold. We
 can rely on the same squarepixel threshold introduced as part of #58235
 used for `fetchpriority="high"` here.

 The proposed fix is as follows: For the two conditions where images have
 lazy-loading omitted before the loop (i.e. the `template_part_header`
 context clause for block themes, and the `$wp_query->before_loop` clause
 for classic themes), the image should be counted towards the lazy-loading
 threshold ''if'' its size is greater than the minimum squarepixel
 threshold from the `wp_min_priority_img_pixels` filter.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58635>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list