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]
+
+  <IfModule mod_mime.c>
+    # 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).
+    <FilesMatch "\.css\.gz$">
+      ForceType text/css
+    </FilesMatch>
+
+    # Serve gzip compressed JS files as 'text/javascript' (for newer Apache).
+    <FilesMatch "\.js\.gz$">
+      ForceType text/javascript
+    </FilesMatch>
+
+    # Send any files ending in .gz with gzip encoding in the header.
+    AddEncoding gzip .gz
+  </IfModule>
 </IfModule>
 
 # $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;
Index: modules/system/system.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.admin.inc,v
retrieving revision 1.188
diff -u -u -p -r1.188 system.admin.inc
--- modules/system/system.admin.inc	22 Aug 2009 20:01:10 -0000	1.188
+++ modules/system/system.admin.inc	22 Aug 2009 21:01:33 -0000
@@ -1447,12 +1447,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';
