Make WordPress Core


Ignore:
Timestamp:
08/25/2024 11:47:01 PM (10 months ago)
Author:
peterwilsoncc
Message:

Script Loader: Refactor Etag generation for concatenated assets.

Move Etag HTTP header generation in load-scripts.php and load-styles.php to WP_Dependencies.

Introduces the method WP_Dependencies::get_etag() and associated unit tests.

Follow up to [57943].

Props vrajadas, martinkrcho, mukesh27.
Fixes #61485.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/load-scripts.php

    r58905 r58935  
    5353wp_default_packages_scripts( $wp_scripts );
    5454
    55 $etag = "WP:{$wp_version};";
    56 
    57 foreach ( $load as $handle ) {
    58     if ( ! array_key_exists( $handle, $wp_scripts->registered ) ) {
    59         continue;
    60     }
    61 
    62     $ver   = $wp_scripts->registered[ $handle ]->ver ? $wp_scripts->registered[ $handle ]->ver : $wp_version;
    63     $etag .= "{$handle}:{$ver};";
    64 }
    65 
    66 /*
    67  * This is not intended to be cryptographically secure, just a fast way to get
    68  * a fixed length string based on the script versions. As this file does not
    69  * load the full WordPress environment, it is not possible to use the salted
    70  * wp_hash() function.
    71  */
    72 $etag = 'W/"' . md5( $etag ) . '"';
     55$etag = $wp_scripts->get_etag( $load );
    7356
    7457if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $etag ) {
Note: See TracChangeset for help on using the changeset viewer.