gzip without mod_gzip
Posted: Wed Jun 06, 2007 2:06 pm
I usually don't have to concern myself with gzipping content and the idiosyncrasies of various browsers with regard to gzip content because it's usually not an option on shared servers. However, I started thinking there must be a way to serve gzip content even on a shared server without using a module. It's just content!? After some Googling I've come up with a couples articles for doing just that:
Compress JavaScript and CSS without touching your application code
How to get Apache to send compressed versions of static HTML files
Compressing moo.tools (javascript) even further
Compressed JavaScript (For the User Comments not the article)
Since I already have a build process in place it should be easy to generate the gzip files for HTML, JS and CSS. What to serve, to which browser is the problem.
Are there any other RewriteCond I should include? I can't think of any problem with gzipping HTML and CSS, are there any problems? I'm think I need a Vary header too?
Anybody else using this kind of setup?
Compress JavaScript and CSS without touching your application code
How to get Apache to send compressed versions of static HTML files
Compressing moo.tools (javascript) even further
Compressed JavaScript (For the User Comments not the article)
Since I already have a build process in place it should be easy to generate the gzip files for HTML, JS and CSS. What to serve, to which browser is the problem.
Code: Select all
<filesmatch "\.js.gz$">
ForceType text/javascript
Header set Content-Encoding: gzip
</filesmatch>
<filesmatch "\.js$">
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} !".*Safari.*"
RewriteCond %{HTTP_USER_AGENT} !".*MSIE 4.*"
RewriteCond %{HTTP_USER_AGENT} !".*MSIE 5.*"
RewriteCond %{HTTP_USER_AGENT} !".*MSIE 6.*"
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule (.*).js$ $1.js.gz [L]
ForceType text/javascript
</filesmatch>
<filesmatch "\.html.gz$">
ForceType text/html
Header set Content-Encoding: gzip
</filesmatch>
<filesmatch "\.html$">
RewriteEngine On
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule (.*).html$ $1.html.gz [L]
ForceType text/html
</filesmatch>
<filesmatch "\.css.gz$">
ForceType text/css
Header set Content-Encoding: gzip
</filesmatch>
<filesmatch "\.css$">
RewriteEngine On
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}.gz -f
RewriteRule (.*).css$ $1.css.gz [L]
ForceType text/css
</filesmatch>
Anybody else using this kind of setup?