? drupal-101227-107-css-js-gzip.patch ? drupal-101227-109-css-js-gzip.patch Index: .htaccess =================================================================== RCS file: /cvs/drupal/drupal/.htaccess,v retrieving revision 1.90.2.5 diff -u -p -r1.90.2.5 .htaccess --- .htaccess 2 Feb 2010 07:25:22 -0000 1.90.2.5 +++ .htaccess 28 Jun 2010 03:46:50 -0000 @@ -111,6 +111,47 @@ DirectoryIndex index.php 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 + + + # Force proxies to cache both gzipped & not gzipped css/js files + + + Header append Vary Accept-Encoding + + + # If mod_headers not installed, disable client cache via mod_expires + + ExpiresDefault A0 + + + + + # Send any files ending in .gz with gzip encoding in the header. + AddEncoding gzip .gz + # $Id: .htaccess,v 1.90.2.5 2010/02/02 07:25:22 dries Exp $ Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.756.2.89 diff -u -p -r1.756.2.89 common.inc --- includes/common.inc 2 Jun 2010 18:58:25 -0000 1.756.2.89 +++ includes/common.inc 28 Jun 2010 03:46:51 -0000 @@ -3224,6 +3224,15 @@ function drupal_get_schema($table = NULL drupal_alter('schema', $schema); cache_set('schema', $schema); } + // If CSS gzip compression is enabled, clean URLs are enabled (which means + // that rewrite rules are working) and the 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; + } + } } if (!isset($table)) { @@ -3658,6 +3667,15 @@ function drupal_explode_tags($tags) { if ($tag != "") { $tags[] = $tag; } + // If JS gzip compression is enabled, clean URLs are enabled (which means + // that rewrite rules are working) and the 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 $tags; Index: sites/default/default.settings.php =================================================================== RCS file: /cvs/drupal/drupal/sites/default/default.settings.php,v retrieving revision 1.8.2.4 diff -u -p -r1.8.2.4 default.settings.php --- sites/default/default.settings.php 14 Sep 2009 12:59:18 -0000 1.8.2.4 +++ sites/default/default.settings.php 28 Jun 2010 03:46:51 -0000 @@ -225,6 +225,21 @@ ini_set('url_rewriter.tags', ''); # ); /** + * 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