Make WordPress Core

Changeset 57789


Ignore:
Timestamp:
03/07/2024 07:06:53 AM (9 months ago)
Author:
adamsilverstein
Message:

Script loader: enable fetchpriority attribute in the wp_preload_resources filter.

Add fetchpriority to the attributes accepted by the wp_preload_resources filter. Developers can now use this filter to set fetchpriority for resources being preloaded.

Props nihar007, luboslives, tabrisrp.
Fixes #58510.

Location:
trunk
Files:
2 edited

Legend:

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

    r57644 r57789  
    35803580     *
    35813581     * @since 6.1.0
     3582     * @since 6.6.0 Added the `$fetchpriority` attribute.
    35823583     *
    35833584     * @param array  $preload_resources {
     
    35873588     *         Array of resource attributes.
    35883589     *
    3589      *         @type string $href        URL to include in resource preloads. Required.
    3590      *         @type string $as          How the browser should treat the resource
    3591      *                                   (`script`, `style`, `image`, `document`, etc).
    3592      *         @type string $crossorigin Indicates the CORS policy of the specified resource.
    3593      *         @type string $type        Type of the resource (`text/html`, `text/css`, etc).
    3594      *         @type string $media       Accepts media types or media queries. Allows responsive preloading.
    3595      *         @type string $imagesizes  Responsive source size to the source Set.
    3596      *         @type string $imagesrcset Responsive image sources to the source set.
     3590     *         @type string $href          URL to include in resource preloads. Required.
     3591     *         @type string $as            How the browser should treat the resource
     3592     *                                     (`script`, `style`, `image`, `document`, etc).
     3593     *         @type string $crossorigin   Indicates the CORS policy of the specified resource.
     3594     *         @type string $type          Type of the resource (`text/html`, `text/css`, etc).
     3595     *         @type string $media         Accepts media types or media queries. Allows responsive preloading.
     3596     *         @type string $imagesizes    Responsive source size to the source Set.
     3597     *         @type string $imagesrcset   Responsive image sources to the source set.
     3598     *         @type string $fetchpriority Fetchpriority value for the resource.
    35973599     *     }
    35983600     * }
     
    36423644
    36433645            // Ignore non-supported attributes.
    3644             $non_supported_attributes = array( 'as', 'crossorigin', 'href', 'imagesrcset', 'imagesizes', 'type', 'media' );
     3646            $non_supported_attributes = array( 'as', 'crossorigin', 'href', 'imagesrcset', 'imagesizes', 'type', 'media', 'fetchpriority' );
    36453647            if ( ! in_array( $resource_key, $non_supported_attributes, true ) && ! is_numeric( $resource_key ) ) {
    36463648                continue;
  • trunk/tests/phpunit/tests/general/wpPreloadResources.php

    r56547 r57789  
    248248                ),
    249249            ),
     250            'fetchpriority'          => array(
     251                'expected'  => "<link rel='preload' href='https://example.com/image.jpg' as='image' fetchpriority='high' />\n",
     252                'resources' => array(
     253                    array(
     254                        'href'          => 'https://example.com/image.jpg',
     255                        'as'            => 'image',
     256                        'fetchpriority' => 'high',
     257                    ),
     258                ),
     259            ),
    250260        );
    251261    }
Note: See TracChangeset for help on using the changeset viewer.