Commit 434752 by dries
- Patch #101227 by mikeytown2, Owen Barton, grendzy: added Gzip aggregated CSS and JS.
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/.htaccess" title="http://drupalcode.org/viewvc/drupal/drupal/.htaccess" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/.htaccess</a> 2010/05/05 06:15:59 1.109
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/.htaccess" title="http://drupalcode.org/viewvc/drupal/drupal/.htaccess" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/.htaccess</a> 2010/10/11 23:49:48 1.110
@@ -109,6 +109,31 @@
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_headers to be enabled.
+ <IfModule mod_headers.c>
+ # 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 [QSA]
+
+ # 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 [QSA]
+
+ # Serve correct content types, and prevent mod_deflate double gzip.
+ RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
+ RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
+
+ <FilesMatch "(\.js\.gz|\.css\.gz)$">
+ # Serve correct encoding type.
+ Header append Content-Encoding gzip
+ # Force proxies to cache gzipped & non-gzipped css/js files separately.
+ Header append Vary Accept-Encoding
+ </FilesMatch>
+ </IfModule>
</IfModule>
-# $Id: .htaccess,v 1.108 2010/04/11 18:33:43 dries Exp $
+# $Id: .htaccess,v 1.109 2010/05/05 06:15:59 webchick Exp $
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc</a> 2010/10/09 08:05:15 1.1239
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc</a> 2010/10/11 23:49:48 1.1240
@@ -3366,6 +3366,15 @@
if (!file_exists($uri) && !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 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_exists($uri . '.gz') && !file_unmanaged_save_data(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) {
+ return FALSE;
+ }
+ }
// Save the updated map.
$map[$key] = $uri;
variable_set('drupal_css_cache_files', $map);
@@ -4655,9 +4664,18 @@
$uri = $jspath . '/' . $filename;
// Create the JS file.
file_prepare_directory($jspath, FILE_CREATE_DIRECTORY);
- if (!file_unmanaged_save_data($contents, $uri, FILE_EXISTS_REPLACE)) {
+ if (!file_exists($uri) && !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 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_exists($uri . '.gz') && !file_unmanaged_save_data(gzencode($contents, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) {
+ return FALSE;
+ }
+ }
$map[$key] = $uri;
variable_set('drupal_js_cache_files', $map);
}
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/INSTALL.txt" title="http://drupalcode.org/viewvc/drupal/drupal/INSTALL.txt" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/INSTALL.txt</a> 2010/09/22 01:49:17 1.83
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/INSTALL.txt" title="http://drupalcode.org/viewvc/drupal/drupal/INSTALL.txt" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/INSTALL.txt</a> 2010/10/11 23:49:48 1.84
@@ -44,6 +44,9 @@
Clean URLs support on IIS, see "Using Clean URLs with IIS"
(<a href="http://drupal.org/node/3854" title="http://drupal.org/node/3854" rel="nofollow">http://drupal.org/node/3854</a>) in the Drupal handbook.
+- To serve gzip compressed CSS and JS files on an Apache web server, you will
+ need the mod_headers module and the ability to use local .htaccess files.
+
- Various Drupal features require that the web server process (for
example, httpd) be able to initiate outbound connections. This is usually
possible, but some hosting providers or server configurations forbid such
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/sites/default/default.settings.php" title="http://drupalcode.org/viewvc/drupal/drupal/sites/default/default.settings.php" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/sites/default/default.setting...</a> 2010/08/08 19:35:49 1.50
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/sites/default/default.settings.php" title="http://drupalcode.org/viewvc/drupal/drupal/sites/default/default.settings.php" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/sites/default/default.setting...</a> 2010/10/11 23:49:48 1.51
@@ -378,6 +378,21 @@
# $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
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/.htaccess" title="http://drupalcode.org/viewvc/drupal/drupal/.htaccess" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/.htaccess</a> 2010/10/11 23:49:48 1.110
@@ -109,6 +109,31 @@
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_headers to be enabled.
+ <IfModule mod_headers.c>
+ # 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 [QSA]
+
+ # 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 [QSA]
+
+ # Serve correct content types, and prevent mod_deflate double gzip.
+ RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
+ RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
+
+ <FilesMatch "(\.js\.gz|\.css\.gz)$">
+ # Serve correct encoding type.
+ Header append Content-Encoding gzip
+ # Force proxies to cache gzipped & non-gzipped css/js files separately.
+ Header append Vary Accept-Encoding
+ </FilesMatch>
+ </IfModule>
</IfModule>
-# $Id: .htaccess,v 1.108 2010/04/11 18:33:43 dries Exp $
+# $Id: .htaccess,v 1.109 2010/05/05 06:15:59 webchick Exp $
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc</a> 2010/10/09 08:05:15 1.1239
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc</a> 2010/10/11 23:49:48 1.1240
@@ -3366,6 +3366,15 @@
if (!file_exists($uri) && !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 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_exists($uri . '.gz') && !file_unmanaged_save_data(gzencode($data, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) {
+ return FALSE;
+ }
+ }
// Save the updated map.
$map[$key] = $uri;
variable_set('drupal_css_cache_files', $map);
@@ -4655,9 +4664,18 @@
$uri = $jspath . '/' . $filename;
// Create the JS file.
file_prepare_directory($jspath, FILE_CREATE_DIRECTORY);
- if (!file_unmanaged_save_data($contents, $uri, FILE_EXISTS_REPLACE)) {
+ if (!file_exists($uri) && !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 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_exists($uri . '.gz') && !file_unmanaged_save_data(gzencode($contents, 9, FORCE_GZIP), $uri . '.gz', FILE_EXISTS_REPLACE)) {
+ return FALSE;
+ }
+ }
$map[$key] = $uri;
variable_set('drupal_js_cache_files', $map);
}
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/INSTALL.txt" title="http://drupalcode.org/viewvc/drupal/drupal/INSTALL.txt" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/INSTALL.txt</a> 2010/09/22 01:49:17 1.83
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/INSTALL.txt" title="http://drupalcode.org/viewvc/drupal/drupal/INSTALL.txt" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/INSTALL.txt</a> 2010/10/11 23:49:48 1.84
@@ -44,6 +44,9 @@
Clean URLs support on IIS, see "Using Clean URLs with IIS"
(<a href="http://drupal.org/node/3854" title="http://drupal.org/node/3854" rel="nofollow">http://drupal.org/node/3854</a>) in the Drupal handbook.
+- To serve gzip compressed CSS and JS files on an Apache web server, you will
+ need the mod_headers module and the ability to use local .htaccess files.
+
- Various Drupal features require that the web server process (for
example, httpd) be able to initiate outbound connections. This is usually
possible, but some hosting providers or server configurations forbid such
--- <a href="http://drupalcode.org/viewvc/drupal/drupal/sites/default/default.settings.php" title="http://drupalcode.org/viewvc/drupal/drupal/sites/default/default.settings.php" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/sites/default/default.setting...</a> 2010/08/08 19:35:49 1.50
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/sites/default/default.settings.php" title="http://drupalcode.org/viewvc/drupal/drupal/sites/default/default.settings.php" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/sites/default/default.setting...</a> 2010/10/11 23:49:48 1.51
@@ -378,6 +378,21 @@
# $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