Art of Scaling

24 December 2007

GZipping CSS and JS files in Apache

GZipping text files on your server can increase response time to the user by shrinking the amount of data that goes across the pipe. Unfortunately, most hosts/servers do not have this on by default. There are a couple cons to using gzip, but overall, it is a worthwhile thing to set up. Let's look at the easiest way to get this done.

Inside your .htaccess file (assuming you are using apache), you need to merely add the lines:

CODE:
  1. # compress content with type html, text, and css
  2. AddOutputFilterByType DEFLATE text/css text/javascript application/x-javascript
  3.  
  4. # properly handle requests coming from behind proxies
  5. Header append Vary User-Agent

Note that it is inadvisable to gZip image files. It is also important to note that gzipping components can increase server CPU load.

Related posts:

  1. Adding an Expires Header
  2. Post Onload Download for better user loadtime

No Comments currently posted.

Post a comment on this entry: