If you follow the instructions on the Yahoo! YSlow best practices, one of them is to compress your pages using gzip compression (“Gzip components”). By doing this, you compress all your files before they are sent across the web, and then the browser decompresses them on the other side. This can significantly improve the time it takes your website to load.
How to Compress a Website with GZip and HTaccess
First check that your site is not already compressed. Some hosting providers do this automatically.
Go to GID Zip Test and enter your URL. If it returns that your site is compressed, you’re done.
If your site is not compressed, you need to know what web server you’re using. If you’re not sure, ask your hosting provider, but the most common web server is Apache. Chances are, that is what your site uses too.
Compress Files on Apache
- Go to the root directory of your web server and edit the
.htaccessfile in a text editor. If you can’t see that file, first make sure that hidden files are visible and if it’s still not there, then you should create a file with that name—including the dot (.) at the beginning of the file.
- Add the following lines to the file:
- Upload the
.htaccessfile to the same location on your website (typically the root folder).
- Test your site again using the GID Zip Test site.
If Your Apache Site Still Isn’t Compressed
Many hosting providers use virtual hosts for web hosting, and sometimes these don’t always recognize all commands in the
.htaccess file. Your best bet is to talk to your hosting support to see if they can get it running. They will probably have to add the above lines (in step 2) into the
Compress Files on IIS
I don’t have an IIS server, so I cannot tell you exactly how to do it, but Microsoft has a comprehensive Technet document: Configuring HTTP Compression in IIS 7 that covers: configuring compression, enabling compression of dynamic content, and enabling compression of static content.