Index: .htaccess =================================================================== RCS file: /cvs/drupal/drupal/.htaccess,v retrieving revision 1.107 diff -u -p -u -p -r1.107 .htaccess --- .htaccess 7 Feb 2010 05:20:21 -0000 1.107 +++ .htaccess 9 Apr 2010 19:41:45 -0000 @@ -109,6 +109,34 @@ DirectoryIndex index.php index.html inde RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^ index.php [L] + + + # 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.107 2010/02/07 05:20:21 webchick Exp $ Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.1145 diff -u -p -u -p -r1.1145 common.inc --- includes/common.inc 7 Apr 2010 17:30:43 -0000 1.1145 +++ includes/common.inc 9 Apr 2010 19:41:45 -0000 @@ -3135,6 +3135,15 @@ function drupal_build_css_cache($css, $f if (!file_unmanaged_save_data($data, $uri, FILE_EXISTS_REPLACE)) { return FALSE; } + // If CSS gzip compression is enabled, clean URLs are enabled (which means + // that rewrite rules are working) and he zlib extension is available then + // create a gzipped version of this file. This file is served conditionally + // to browsers that accept gzip using .htaccess rules. + if (variable_get('css_gzip_compression', TRUE) && variable_get('clean_url', 0) && extension_loaded('zlib')) { + if (!file_unmanaged_save_data(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) { + return FALSE; + } + } } return $uri; } @@ -4187,6 +4196,15 @@ function drupal_build_js_cache($files, $ if (!file_unmanaged_save_data($contents, $uri, FILE_EXISTS_REPLACE)) { return FALSE; } + // If JS gzip compression is enabled, clean URLs are enabled (which means + // that rewrite rules are working) and he zlib extension is available then + // create a gzipped version of this file. This file is served conditionally + // to browsers that accept gzip using .htaccess rules. + if (variable_get('js_gzip_compression', TRUE) && variable_get('clean_url', 0) && extension_loaded('zlib')) { + if (!file_unmanaged_save_data(gzencode($contents, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) { + return FALSE; + } + } } return $uri; } Index: sites/default/default.settings.php =================================================================== RCS file: /cvs/drupal/drupal/sites/default/default.settings.php,v retrieving revision 1.44 diff -u -p -u -p -r1.44 default.settings.php --- sites/default/default.settings.php 7 Apr 2010 15:07:59 -0000 1.44 +++ sites/default/default.settings.php 9 Apr 2010 19:41:45 -0000 @@ -356,6 +356,21 @@ ini_set('session.cookie_lifetime', 20000 # $conf['omit_vary_cookie'] = TRUE; /** + * CSS/JS aggregated file gzip compression: + * + * By default, when CSS or JS aggregation and clean URLs are enabled Drupal will + * store a gzip compressed (.gz) copy of the aggregated files. If this file is + * available then rewrite rules in the default .htaccess file will serve these + * files to browsers that accept gzip encoded content. This allows pages to load + * faster for these users and has minimal impact on server load. If you are + * using a webserver other than Apache httpd, or a caching reverse proxy that is + * configured to cache and compress these files itself you may want to uncomment + * one or both of the below lines, which will prevent gzip files being stored. + */ +# $conf['css_gzip_compression'] = FALSE; +# $conf['js_gzip_compression'] = FALSE; + +/** * String overrides: * * To override specific strings on your site with or without enabling locale