Make WordPress Core

Ticket #28722: 28722.2.diff

File 28722.2.diff, 4.1 KB (added by dd32, 10 years ago)
  • src/wp-admin/load-scripts.php

     
    123123
    124124if ( empty($load) )
    125125        exit;
    126126
    127127require(ABSPATH . WPINC . '/script-loader.php');
    128128require(ABSPATH . WPINC . '/version.php');
    129129
    130130$compress = ( isset($_GET['c']) && $_GET['c'] );
    131131$force_gzip = ( $compress && 'gzip' == $_GET['c'] );
    132132$expires_offset = 31536000; // 1 year
    133133$out = '';
    134134
    135135$wp_scripts = new WP_Scripts();
    136136wp_default_scripts($wp_scripts);
    137137
     138if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $wp_version ) {
     139        header('HTTP/1.1 304 Not Modified');
     140        exit();
     141}
     142
    138143foreach( $load as $handle ) {
    139144        if ( !array_key_exists($handle, $wp_scripts->registered) )
    140145                continue;
    141146
    142147        $path = ABSPATH . $wp_scripts->registered[$handle]->src;
    143148        $out .= get_file($path) . "\n";
    144149}
    145150
     151header("Etag: $wp_version");
    146152header('Content-Type: application/x-javascript; charset=UTF-8');
    147153header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
    148154header("Cache-Control: public, max-age=$expires_offset");
    149155
    150156if ( $compress && ! ini_get('zlib.output_compression') && 'ob_gzhandler' != ini_get('output_handler') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) {
    151157        header('Vary: Accept-Encoding'); // Handle proxies
    152158        if ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) {
    153159                header('Content-Encoding: deflate');
    154160                $out = gzdeflate( $out, 3 );
    155161        } elseif ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') ) {
    156162                header('Content-Encoding: gzip');
    157163                $out = gzencode( $out, 3 );
    158164        }
    159165}
    160166
  • src/wp-admin/load-styles.php

     
    9898$load = preg_replace( '/[^a-z0-9,_-]+/i', '', $_GET['load'] );
    9999$load = array_unique( explode( ',', $load ) );
    100100
    101101if ( empty($load) )
    102102        exit;
    103103
    104104$compress = ( isset($_GET['c']) && $_GET['c'] );
    105105$force_gzip = ( $compress && 'gzip' == $_GET['c'] );
    106106$rtl = ( isset($_GET['dir']) && 'rtl' == $_GET['dir'] );
    107107$expires_offset = 31536000; // 1 year
    108108$out = '';
    109109
    110110$wp_styles = new WP_Styles();
    111111wp_default_styles($wp_styles);
    112112
     113if ( isset( $_SERVER['HTTP_IF_NONE_MATCH'] ) && stripslashes( $_SERVER['HTTP_IF_NONE_MATCH'] ) === $wp_version ) {
     114        header('HTTP/1.1 304 Not Modified');
     115        exit();
     116}
     117
    113118foreach( $load as $handle ) {
    114119        if ( !array_key_exists($handle, $wp_styles->registered) )
    115120                continue;
    116121
    117122        $style = $wp_styles->registered[$handle];
    118123        $path = ABSPATH . $style->src;
    119124
    120125        if ( $rtl && ! empty( $style->extra['rtl'] ) ) {
    121126                // All default styles have fully independent RTL files.
    122127                $path = str_replace( '.min.css', '-rtl.min.css', $path );
    123128        }
    124129
    125130        $content = get_file( $path ) . "\n";
    126131
    127132        if ( strpos( $style->src, '/' . WPINC . '/css/' ) === 0 ) {
    128133                $content = str_replace( '../images/', '../' . WPINC . '/images/', $content );
    129134                $content = str_replace( '../js/tinymce/', '../' . WPINC . '/js/tinymce/', $content );
    130135                $content = str_replace( '../fonts/', '../' . WPINC . '/fonts/', $content );
    131136                $out .= $content;
    132137        } else {
    133138                $out .= str_replace( '../images/', 'images/', $content );
    134139        }
    135140}
    136141
     142header("Etag: $wp_version");
    137143header('Content-Type: text/css; charset=UTF-8');
    138144header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
    139145header("Cache-Control: public, max-age=$expires_offset");
    140146
    141147if ( $compress && ! ini_get('zlib.output_compression') && 'ob_gzhandler' != ini_get('output_handler') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ) {
    142148        header('Vary: Accept-Encoding'); // Handle proxies
    143149        if ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') && function_exists('gzdeflate') && ! $force_gzip ) {
    144150                header('Content-Encoding: deflate');
    145151                $out = gzdeflate( $out, 3 );
    146152        } elseif ( false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') && function_exists('gzencode') ) {
    147153                header('Content-Encoding: gzip');
    148154                $out = gzencode( $out, 3 );
    149155        }
    150156}
    151157