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-styles.php

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