Make WordPress Core


Ignore:
Timestamp:
01/15/2016 10:22:24 AM (9 years ago)
Author:
swissspidy
Message:

Script Loader: Add Etag: $wp_version header in load-scripts.php and load-styles.php.

This improves performance since browsers won't re-download the scripts and styles when there was no change in $wp_version.

Props sergej.mueller, dd32, swissspidy.
Fixes #28722.

File:
1 edited

Legend:

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

    r34037 r36312  
    3434wp_default_scripts($wp_scripts);
    3535
     36if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $wp_version ) {
     37    $protocol = $_SERVER['SERVER_PROTOCOL'];
     38    if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) {
     39        $protocol = 'HTTP/1.0';
     40    }
     41    header( "$protocol 304 Not Modified" );
     42    exit();
     43}
     44
    3645foreach ( $load as $handle ) {
    3746    if ( !array_key_exists($handle, $wp_scripts->registered) )
     
    4251}
    4352
     53header("Etag: $wp_version");
    4454header('Content-Type: application/javascript; charset=UTF-8');
    4555header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
Note: See TracChangeset for help on using the changeset viewer.