[wp-trac] [WordPress Trac] #58211: Conditionally skip lazy-loading on images before the loop in classic themes

WordPress Trac noreply at wordpress.org
Mon May 22 19:11:51 UTC 2023


#58211: Conditionally skip lazy-loading on images before the loop in classic themes
-------------------------------------------------+-------------------------
 Reporter:  flixos90                             |       Owner:  flixos90
     Type:  defect (bug)                         |      Status:  closed
 Priority:  high                                 |   Milestone:  6.3
Component:  Media                                |     Version:  5.9
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests has-        |     Focuses:
  testing-info commit                            |  performance
-------------------------------------------------+-------------------------
Changes (by flixos90):

 * status:  reviewing => closed
 * resolution:   => fixed


Comment:

 In [changeset:"55847" 55847]:
 {{{
 #!CommitTicketReference repository="" revision="55847"
 Media: Conditionally skip lazy-loading on images before the loop to
 improve LCP performance.

 When the logic to exclude images that likely appear above the fold from
 being lazy-loaded was introduced in WordPress 5.9, initially only images
 that appear within the main query loop were being considered. However,
 there is a good chance that images above the fold are rendered before the
 loop starts, for example in the header template part.

 It is particularly common for a theme to display the featured image for a
 single post in the header. Based on HTTP Archive data from February 2023,
 the majority of LCP images that are still being lazy-loaded on WordPress
 sites use the `wp-post-image` class, i.e. are featured images.

 This changeset enhances the logic in `wp_get_loading_attr_default()` to
 not lazy-load images that appear within or after the header template part
 and before the query loop, using a new `WP_Query::$before_loop` property.

 For block themes, this was for the most part already addressed in [55318],
 however this enhancement implements the solution in a more generally
 applicable way that brings the improvement to classic themes as well.

 Props thekt12, flixos90, spacedmonkey, costdev, zunaid321, mukesh27.
 Fixes #58211.
 See #53675, #56930.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58211#comment:13>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list