? gzip-101227-78.patch
? gzip-101227-81.patch
Index: .htaccess
===================================================================
RCS file: /cvs/drupal/drupal/.htaccess,v
retrieving revision 1.104
diff -u -p -r1.104 .htaccess
--- .htaccess 16 Aug 2009 12:10:36 -0000 1.104
+++ .htaccess 20 Aug 2009 17:08:56 -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
@@ -58,6 +68,12 @@ DirectoryIndex index.php index.html inde
+# Requires mod_mime to be enabled.
+
+ # Send any files ending in .gz with gzip encoding in the header.
+ AddEncoding gzip .gz
+
+
# Various rewrite rules.
RewriteEngine on
@@ -93,6 +109,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.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.964
diff -u -p -r1.964 common.inc
--- includes/common.inc 19 Aug 2009 20:19:36 -0000 1.964
+++ includes/common.inc 20 Aug 2009 17:08:57 -0000
@@ -2678,6 +2678,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;
}
@@ -3376,6 +3382,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.180
diff -u -p -r1.180 system.admin.inc
--- modules/system/system.admin.inc 17 Aug 2009 19:14:41 -0000 1.180
+++ modules/system/system.admin.inc 20 Aug 2009 17:08:58 -0000
@@ -1412,12 +1412,30 @@ function system_performance_settings() {
'#default_value' => intval(variable_get('preprocess_css', 0) && $is_writable),
'#disabled' => $disabled,
);
+ if (variable_get('preprocess_css', 0)) {
+ $form['bandwidth_optimization']['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_optimization']['preprocess_js'] = array(
'#type' => 'checkbox',
'#title' => t('Aggregate JavaScript files into one file.'),
'#default_value' => intval(variable_get('preprocess_js', 0) && $is_writable),
'#disabled' => $disabled,
);
+ if (variable_get('preprocess_js', 0)) {
+ $form['bandwidth_optimization']['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['#submit'][] = 'drupal_clear_css_cache';
$form['#submit'][] = 'drupal_clear_js_cache';