Make WordPress Core


Ignore:
Timestamp:
05/16/2023 06:50:11 PM (19 months ago)
Author:
flixos90
Message:

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.

Props thekt12, spacedmonkey, westonruter, flixos90.
Fixes #58213.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r55764 r55816  
    54365436 * Under the hood, the function uses {@see wp_increase_content_media_count()} every time it is called for an element
    54375437 * within the main content. If the element is the very first content element, the `loading` attribute will be omitted.
    5438  * This default threshold of 1 content element to omit the `loading` attribute for can be customized using the
     5438 * This default threshold of 3 content elements to omit the `loading` attribute for can be customized using the
    54395439 * {@see 'wp_omit_loading_attr_threshold'} filter.
    54405440 *
     
    54865486 * Gets the threshold for how many of the first content media elements to not lazy-load.
    54875487 *
    5488  * This function runs the {@see 'wp_omit_loading_attr_threshold'} filter, which uses a default threshold value of 1.
     5488 * This function runs the {@see 'wp_omit_loading_attr_threshold'} filter, which uses a default threshold value of 3.
    54895489 * The filter is only run once per page load, unless the `$force` parameter is used.
    54905490 *
     
    55075507         *
    55085508         * @since 5.9.0
     5509         * @since 6.3.0 The default threshold was changed from 1 to 3.
    55095510         *
    5510          * @param int $omit_threshold The number of media elements where the `loading` attribute will not be added. Default 1.
     5511         * @param int $omit_threshold The number of media elements where the `loading` attribute will not be added. Default 3.
    55115512         */
    5512         $omit_threshold = apply_filters( 'wp_omit_loading_attr_threshold', 1 );
     5513        $omit_threshold = apply_filters( 'wp_omit_loading_attr_threshold', 3 );
    55135514    }
    55145515
Note: See TracChangeset for help on using the changeset viewer.