[wp-hackers] compression and caching

William Canino william.canino at googlemail.com
Mon Dec 28 21:22:29 UTC 2009


Let me share with you guys my .htaccess file. I got more gains with
this config in my experience than minifying and concatenating on the
fly hereby killing the CPU of my shared host.

# Far Expires
FileETag All
ExpiresActive On  # enable expirations
ExpiresByType text/javascript "access plus 5 weeks"
ExpiresByType application/x-javascript "access plus 5 weeks"
ExpiresByType application/javascript "access plus 5 weeks"
ExpiresByType text/css "access plus 5 weeks"

# Javascript and CSS Gzipping
# copied from http://zuble.blogspot.com/2007/02/compressed-js-and-modrewrite.html
<FilesMatch "\\.js.gz$">
  ForceType text/javascript
  Header set Content-Encoding: gzip
</FilesMatch>
<FilesMatch "\\.js$">
  RewriteEngine On
  RewriteCond %{HTTP:Accept-Encoding} gzip
  RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
  RewriteCond %{REQUEST_FILENAME}.gz -f
  RewriteRule (.*)\.js$ $1\.js.gz [L]
  ForceType text/javascript
</FilesMatch>
<FilesMatch "\\.css.gz$">
  ForceType text/css
  Header set Content-Encoding: gzip
</FilesMatch>
<FilesMatch "\\.css$">
  RewriteEngine On
  RewriteCond %{HTTP:Accept-Encoding} gzip
  RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
  RewriteCond %{REQUEST_FILENAME}.gz -f
  RewriteRule (.*)\.css$ $1\.css.gz [L]
  ForceType text/css
</FilesMatch>

I then saved a minified+gzipped version of each css and js on the
respective directories.

Don't joke -- I *have* killed a shared hosting CPU before by
dynamically concatenating, minifying and compressing assets.


More information about the wp-hackers mailing list