Apache 2 uses mod_deflate to quickly and easily compress your static .css and .js files before you send them to a client. This speeds up your site like crazy!
Easy Apache Speed Tips Articles
- Turn On Compression
- Add Future Expires Header
- Add Cache-Control Headers
- Turn Off ETags
- Remove Last-Modified Header
- Use Multiple SubDomains
Turn Gzip Compression On
This goes in your root .htaccess file but if you have access to httpd.conf that is better.
This code uses the FilesMatch directive and the SetOutputFilter DEFLATE directive to only target files ending in .js or .css
<IfModule mod_deflate.c> <FilesMatch "\.(js|css)$"> SetOutputFilter DEFLATE </FilesMatch> </IfModule>
Without mod_deflate
With mod_deflate
Bandwidth Savings
mod_deflate gzip compress deflate speed htaccess compression setoutputfilter
Related Articles
09.25.07 at 3:07 am
My site throws up a 500 error when I do this. Any suggestions?
11.06.07 at 8:31 am
My site ALSO throws an Error 500.
I can’t see a problem with the code, so something has to be set at the server to accept this, right?
11.09.07 at 9:42 am
If you get an 500 internal server error, means that your server don’t have mod_expire.so and mod_headers.so loaded. Edit your httpd.conf and add these lines :
Cheers
04.07.08 at 8:59 pm
When I added the above code, I was given an internal server error. I am not sure why? Any suggestions?
04.08.08 at 11:35 am
@ All
Sorry for the delay people, I just updated the code to prevent the 500 error, which is telling you that you don’t have the deflate module. At least now you know which module you are missing!
04.18.08 at 8:48 am
I am trying to add gzip compression for a friends site which is WP. I already set up compression for php files using php.ini. However, I can’t get the js|CSS to work. Any suggestions. The site is hosted with Godaddy, apache of course.
04.19.08 at 12:07 am
@ jason ~
Sounds like you don’t have mod_deflate. I need more info like error messages, how you know its not working, and current .htaccess if I were going to answer.
04.19.08 at 6:31 am
Thanks for your attention:
My .htaccess file:
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
#12 Months
Header set Cache-Control “max-age=29030400, public”
Header unset ETag
FileETag None
# 2 HOURS
Header set Cache-Control “max-age=7200, must-revalidate”
SetOutputFilter DEFLATE
I am not getting an error. It is just not working with the css and js according to yslow. I was able to set a php.ini file to gzip the php. Although, I am not sure how to do the same thing for the css/js.