This repository has been archived by the owner on Mar 9, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WP-r55850: Media: Fix bug in lazy-loading of images in excerpts (#274)
* WP-r55816: Media: Increase default for `wp_omit_loading_attr_threshold` to 3. The previous default threshold for how many content images to skip lazy-loading on (which was just 1) has proven to be too strict: HTTP Archive data shows that >70% of sites have up to 3 equal-sized images in the initial viewport, each of which could be the LCP image and therefore should not be lazy-loaded. Lazy-loading too many images has adverse effects on load time performance, while increasing the default threshold will not negatively affect load time performance even for sites where a threshold of 1 would be the perfect choice. The change of default value in this changeset will improve performance for more WordPress sites out of the box. The `wp_omit_loading_attr_threshold` filter can still be used to customize and fine tune the value where needed. WP:Props thekt12, spacedmonkey, westonruter, flixos90. Fixes https://core.trac.wordpress.org/ticket/58213. Conflicts: - tests/phpunit/tests/media.php --- Merges https://core.trac.wordpress.org/changeset/55816 / WordPress/wordpress-develop@a56a83fc6c to ClassicPress. * Fix merge conflicts from 55816 * WP-r55847: 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 https://core.trac.wordpress.org/changeset/55318, however this enhancement implements the solution in a more generally applicable way that brings the improvement to classic themes as well. WP:Props thekt12, flixos90, spacedmonkey, costdev, zunaid321, mukesh27. Fixes https://core.trac.wordpress.org/ticket/58211. See https://core.trac.wordpress.org/ticket/53675, https://core.trac.wordpress.org/ticket/56930. Conflicts: - src/wp-includes/media.php - tests/phpunit/tests/media.php --- Merges https://core.trac.wordpress.org/changeset/55847 / WordPress/wordpress-develop@71140f327f to ClassicPress. * Fix merge conflicts from 55847 * WP-r55850: Media: Fix lazy-loading bug by avoiding to modify content images when creating an excerpt. The `wp_filter_content_tags()` function, which modifies image tags for example to optimize performance, is hooked into the `the_content` filter by default. When rendering an excerpt for a post that doesn't have a manually provided excerpt, the post content is used to generate the excerpt, handled by the `wp_trim_excerpt()` function. Prior to this changeset, this led to `wp_filter_content_tags()` being called on the content when generating the excerpt, which is wasteful as all tags are stripped from the excerpt, and it furthermore could result in a lazy-loading bug when the post content contained images, as those images were being counted even though they would never be rendered as part of the excerpt. This changeset fixes the bug and slightly improves performance for generating an excerpt by temporarily unhooking the `wp_filter_content_tags()` function from the `the_content` filter when using it to generate the excerpt. WP:Props costdev, flixos90, joemcgill, mukesh27, salvoaranzulla, spacedmonkey, thekt12, westonruter. Fixes https://core.trac.wordpress.org/ticket/56588. Conflicts: - tests/phpunit/tests/media.php --- Merges https://core.trac.wordpress.org/changeset/55850 / WordPress/wordpress-develop@6ff355e87d to ClassicPress. * Fix merge conflicts in 55850 * WP-r55825: Media: Prevent special images within post content to skew image counts and cause lazy-loading bugs. In order to skip lazy-loading the first few images on a page, as of WordPress 5.9 there has been logic to count images that are eligible based on certain criteria. One of those groups are images that appear within the content of a post. This changeset fixes a bug where images created via `get_the_post_thumbnail()` or `wp_get_attachment_image()` that are injected into the post content would skew the count and therefore result in all images to be lazy-loaded, potentially hurting load time performance. This is relevant for example when those functions are called in server-side rendered blocks, or any other filter callbacks hooked into `the_content`. WP:Props flixos90, antpb, joedolson, spacedmonkey, mukesh27, thekt12, costdev, jrf. Fixes https://core.trac.wordpress.org/ticket/58089. See https://core.trac.wordpress.org/ticket/53675. --- Merges https://core.trac.wordpress.org/changeset/55825 / WordPress/wordpress-develop@23b007b126 to ClassicPress. * Removed duplicated test from 55825 --------- Co-authored-by: Felix Arntz <[email protected]>
- Loading branch information