Index: .htaccess =================================================================== RCS file: /cvs/drupal/drupal/.htaccess,v retrieving revision 1.104 diff -u -u -p -r1.104 .htaccess --- .htaccess 16 Aug 2009 12:10:36 -0000 1.104 +++ .htaccess 22 Aug 2009 21:01:32 -0000 @@ -93,6 +93,34 @@ DirectoryIndex index.php index.html inde RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] + + + # Rules to correctly serve gzip compressed CSS and JS files. + # Requires both mod_rewrite and mod_mime to be enabled. + + # Serve gzip compressed CSS files if they exist and the client accepts gzip. + RewriteCond %{HTTP:Accept-encoding} gzip + RewriteCond %{REQUEST_FILENAME}\.gz -s + RewriteRule ^(.*)\.css $1\.css\.gz [L,QSA,T=text/css] + + # Serve gzip compressed JS files if they exist and the client accepts gzip. + RewriteCond %{HTTP:Accept-encoding} gzip + RewriteCond %{REQUEST_FILENAME}\.gz -s + RewriteRule ^(.*)\.js $1\.js\.gz [L,QSA,T=text/javascript] + + # Serve gzip compressed CSS files as 'text/css' (for newer Apache). + + ForceType text/css + + + # Serve gzip compressed JS files as 'text/javascript' (for newer Apache). + + ForceType text/javascript + + + # Send any files ending in .gz with gzip encoding in the header. + AddEncoding gzip .gz + # $Id: .htaccess,v 1.104 2009/08/16 12:10:36 dries Exp $ Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.968 diff -u -u -p -r1.968 common.inc --- includes/common.inc 22 Aug 2009 19:58:27 -0000 1.968 +++ includes/common.inc 22 Aug 2009 21:01:33 -0000 @@ -2699,6 +2699,12 @@ function drupal_build_css_cache($css, $f // Create the CSS file. file_unmanaged_save_data($data, $csspath . '/' . $filename, FILE_EXISTS_REPLACE); + if (variable_get('css_gzip_compression', TRUE) && function_exists('gzencode') && zlib_get_coding_type() == FALSE) { + // If CSS gzip compression is enabled and the gzencode function exits and + // output compression is disabled then create a gzipped version of the + // above file. + file_unmanaged_save_data(gzencode($data, 9, FORCE_GZIP), $csspath . '/' . $filename . '.gz', FILE_EXISTS_REPLACE); + } } return $csspath . '/' . $filename; } @@ -3397,6 +3403,12 @@ function drupal_build_js_cache($files, $ // Create the JS file. file_unmanaged_save_data($contents, $jspath . '/' . $filename, FILE_EXISTS_REPLACE); + if (variable_get('js_gzip_compression', TRUE) && function_exists('gzencode') && zlib_get_coding_type() == FALSE) { + // If JavaScript gzip compression is enabled and the gzencode function + // exits and output compression is disabled then create a gzipped version + // of the above file. + file_unmanaged_save_data(gzencode($contents, 9, FORCE_GZIP), $jspath . '/' . $filename . '.gz', FILE_EXISTS_REPLACE); + } } return $jspath . '/' . $filename;