Index: .htaccess
===================================================================
RCS file: /cvs/drupal/drupal/.htaccess,v
retrieving revision 1.103
diff -u -p -r1.103 .htaccess
--- .htaccess 21 Jun 2009 10:48:06 -0000 1.103
+++ .htaccess 8 Aug 2009 05:01:02 -0000
@@ -7,6 +7,16 @@
Order allow,deny
+# Gzip compressed CSS files are of the type 'text/css'.
+
+ ForceType text/css
+
+
+# Gzip compressed JS files are of the type 'text/javascript'.
+
+ ForceType text/javascript
+
+
# Don't show directory listings for URLs which map to a directory.
Options -Indexes
@@ -54,6 +64,12 @@ DirectoryIndex index.php index.html inde
+# Requires mod_mime to be enabled.
+
+ # Send any files ending in .gz with x-gzip encoding in the header.
+ AddEncoding x-gzip .gz
+
+
# Various rewrite rules.
RewriteEngine on
@@ -89,6 +105,16 @@ DirectoryIndex index.php index.html inde
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
+
+ # Serve gzip compressed CSS files if they exist
+ 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
+ RewriteCond %{HTTP:Accept-encoding} gzip
+ RewriteCond %{REQUEST_FILENAME}\.gz -s
+ RewriteRule ^(.*)\.js $1\.js\.gz [L,QSA,T=text/javascript]
# $Id: .htaccess,v 1.103 2009/06/21 10:48:06 dries Exp $
Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.954
diff -u -p -r1.954 common.inc
--- includes/common.inc 5 Aug 2009 15:58:34 -0000 1.954
+++ includes/common.inc 8 Aug 2009 05:01:04 -0000
@@ -2627,6 +2627,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;
}
@@ -3324,6 +3330,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;
Index: modules/system/system.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v
retrieving revision 1.169
diff -u -p -r1.169 system.admin.inc
--- modules/system/system.admin.inc 5 Aug 2009 19:40:55 -0000 1.169
+++ modules/system/system.admin.inc 8 Aug 2009 05:01:05 -0000
@@ -1373,6 +1373,13 @@ function system_performance_settings() {
'#options' => array(t('Disabled'), t('Enabled')),
'#description' => t('This option can interfere with theme development and should only be enabled in a production environment.'),
);
+ $form['bandwidth_optimizations']['css_gzip_compression'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Gzip compress CSS aggergated files'),
+ '#default_value' => variable_get('css_gzip_compression', FALSE),
+ '#disabled' => !(function_exists('gzencode') && zlib_get_coding_type() == FALSE),
+ '#description' => t('This option should be disabled when using a webserver that performs compression.'),
+ );
$form['bandwidth_optimizations']['preprocess_js'] = array(
'#type' => 'radios',
'#title' => t('Optimize JavaScript files'),
@@ -1381,6 +1388,13 @@ function system_performance_settings() {
'#options' => array(t('Disabled'), t('Enabled')),
'#description' => t('This option can interfere with module development and should only be enabled in a production environment.'),
);
+ $form['bandwidth_optimizations']['js_gzip_compression'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Gzip compress JavaScript aggergated files'),
+ '#default_value' => variable_get('css_gzip_compression', FALSE),
+ '#disabled' => !(function_exists('gzencode') && zlib_get_coding_type() == FALSE),
+ '#description' => t('This option should be disabled when using a webserver that performs compression.'),
+ );
$form['clear_cache'] = array(
'#type' => 'fieldset',