Use gzip instead of deflate as more servers seem to understand it, add separate switch for disabling CSS compression

git-svn-id: http://svn.automattic.com/wordpress/trunk@10372 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-01-17 14:08:15 +00:00
parent 23587f4c8e
commit b396079aa0
4 changed files with 25 additions and 33 deletions

View File

@ -85,24 +85,19 @@ function get_file($path) {
return @file_get_contents($path);
}
// Discard any buffers
while ( @ob_end_clean() );
if ( isset($_GET['test']) && 1 == $_GET['test'] ) {
if ( ini_get('zlib.output_compression') )
exit('');
$out = 'var wpCompressionTest = 1;';
$compressed = false;
if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'deflate') && function_exists('gzdeflate') ) {
header('Content-Encoding: deflate');
$out = gzdeflate( $out, 3 );
$compressed = true;
} elseif ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && function_exists('gzencode') ) {
if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && function_exists('gzencode') ) {
header('Content-Encoding: gzip');
$out = gzencode( $out, 3 );
$compressed = true;
$out = gzencode( 'var wpCompressionTest = 1;', 3 );
}
if ( ! $compressed )
if ( ! isset($out) )
exit('');
header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
@ -123,9 +118,6 @@ if ( empty($load) )
require(ABSPATH . '/wp-includes/script-loader.php');
require(ABSPATH . '/wp-includes/version.php');
// Discard any buffers
while ( @ob_end_clean() );
$compress = ( isset($_GET['c']) && 1 == $_GET['c'] );
$expires_offset = 31536000;
$out = '';
@ -142,15 +134,12 @@ foreach( $load as $handle ) {
}
header('Content-Type: application/x-javascript; charset=UTF-8');
header('Vary: Accept-Encoding'); // Handle proxies
header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
header("Cache-Control: public, max-age=$expires_offset");
if ( $compress && ! ini_get('zlib.output_compression') ) {
if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'deflate') && function_exists('gzdeflate') ) {
header('Content-Encoding: deflate');
$out = gzdeflate( $out, 3 );
} elseif ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && function_exists('gzencode') ) {
if ( $compress && ! ini_get('zlib.output_compression') && function_exists('gzencode') ) {
header('Vary: Accept-Encoding'); // Handle proxies
if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') ) {
header('Content-Encoding: gzip');
$out = gzencode( $out, 3 );
}

View File

@ -123,15 +123,12 @@ foreach( $load as $handle ) {
}
header('Content-Type: text/css');
header('Vary: Accept-Encoding'); // Handle proxies
header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expires_offset ) . ' GMT');
header("Cache-Control: public, max-age=$expires_offset");
if ( $compress && ! ini_get('zlib.output_compression') ) {
if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'deflate') && function_exists('gzdeflate') ) {
header('Content-Encoding: deflate');
$out = gzdeflate( $out, 3 );
} elseif ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') && function_exists('gzencode') ) {
if ( $compress && ! ini_get('zlib.output_compression') && function_exists('gzencode') ) {
header('Vary: Accept-Encoding'); // Handle proxies
if ( false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') ) {
header('Content-Encoding: gzip');
$out = gzencode( $out, 3 );
}

View File

@ -1,5 +1,7 @@
<?php
$basepath = dirname(__FILE__);
while ( @ob_end_clean() );
function get_file($path) {
@ -22,8 +24,8 @@ header("Cache-Control: public, max-age=$expires_offset");
if ( isset($_GET['c']) && 1 == $_GET['c'] && ! ini_get('zlib.output_compression') && false !== strpos( strtolower($_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') ) {
header('Content-Encoding: gzip');
echo get_file('wp-tinymce.js.gz');
echo get_file($basepath . '/wp-tinymce.js.gz');
} else {
echo get_file('wp-tinymce.js');
echo get_file($basepath . '/wp-tinymce.js');
}
exit;

View File

@ -596,7 +596,7 @@ function _pring_scripts() {
}
$ver = md5("$wp_scripts->concat" . "$wp_scripts->concat_version");
$src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}&amp;load=" . rtrim($wp_scripts->concat, ',') . "&amp;ver=$ver";
$src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}&load=" . rtrim($wp_scripts->concat, ',') . "&ver=$ver";
echo "<script type='text/javascript' src='$src'></script>\n";
}
@ -606,7 +606,7 @@ function _pring_scripts() {
}
function wp_print_admin_styles() {
global $wp_styles, $concatenate_scripts, $compress_scripts;
global $wp_styles, $concatenate_scripts, $compress_css;
if ( !is_a($wp_styles, 'WP_Styles') )
$wp_styles = new WP_Styles();
@ -615,7 +615,7 @@ function wp_print_admin_styles() {
script_concat_settings();
$wp_styles->do_concat = $concatenate_scripts;
$zip = $compress_scripts ? 1 : 0;
$zip = $compress_css ? 1 : 0;
$wp_styles->do_items(false);
@ -623,7 +623,7 @@ function wp_print_admin_styles() {
if ( !empty($wp_styles->concat) ) {
$ver = md5("$wp_styles->concat" . "$wp_styles->concat_version");
$rtl = 'rtl' === $wp_styles->text_direction ? 1 : 0;
$href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&amp;rtl={$rtl}&amp;load=" . rtrim($wp_styles->concat, ',') . "&amp;ver=$ver";
$href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&rtl={$rtl}&load=" . rtrim($wp_styles->concat, ',') . "&ver=$ver";
echo "<link rel='stylesheet' href='$href' type='text/css' media='all' />\n";
}
@ -637,7 +637,7 @@ function wp_print_admin_styles() {
}
function script_concat_settings() {
global $concatenate_scripts, $compress_scripts;
global $concatenate_scripts, $compress_scripts, $compress_css;
$concatenate_scripts = defined('CONCATENATE_SCRIPTS') ? CONCATENATE_SCRIPTS : true;
if ( $concatenate_scripts && -1 == get_option('concatenate_scripts') )
@ -646,6 +646,10 @@ function script_concat_settings() {
$compress_scripts = defined('COMPRESS_SCRIPTS') ? COMPRESS_SCRIPTS : true;
if ( $compress_scripts && ! get_option('can_compress_scripts') )
$compress_scripts = false;
$compress_css = defined('COMPRESS_CSS') ? COMPRESS_CSS : true;
if ( $compress_css && ! get_option('can_compress_scripts') )
$compress_css = false;
}
add_action( 'wp_default_scripts', 'wp_default_scripts' );