How To Optimize Your Site With GZIP Compression

Compression is a simple, effective way to save bandwidth and speed up your site. I hesitated when recommending gzip compression when speeding up your javascript because of problemsinolder browsers.

This is a companion discussion topic for the original entry at

[…] The benefits of compression are too good to ignore: optimize your site with HTTP compression. […]

[…] I’ve been on a web tweaking kick lately: how to speed up your javascript, gzip files with your server, and now how to set up caching. But the reason is simple: site performance is a feature. […]

Very simple and good guide :slight_smile:


These days, I am working on heavy user interface using GWT. I think, pre-zip compression will help me to compress 100K+ jscript file. Bookmarked.

Great, glad you found it useful!

Thanks for this. Excellent guide.

[…] GZip compression on a website See this webpage on using compression to optimize the web experience. […]

[…] File Compression Using GZIP or Deflate can drastically reduce the downloaded file size (but should be used wisely). You can read more on this here. […]

Wow, it’s useful and easy to understand!

Anyway, I found this topic when using CURL to download pages. This library supports compress natively. Just enable it like this :

This is a very good guide. However, I have a question. What if I want to compress more than one file type using my .htaccess file? Do I need to separate the file types with a space, or a comma, or something else? For example,

<Files *.html *.php>
SetOutputFilter DEFLATE


SetOutputFilter DEFLATE

Hi Elias, great question. Unfortunately Apache doesn’t make it easy to include multiple types. The brute-force way is to have two sections, one for .php and another for .html.

The “official” way uses “FilesMatch” to match files by a regular expression:

SetOutputFilter DEFLATE

The regular expression “.(php|html)$” means: a dot character, followed by “php” or “html”, followed by the end of the line. This matches both *.html and *.php – if you wanted more you’d write something like “.(php|html|txt|css)$”.

Hope this helps!

Thanks for the helpful article. I have a simple question: what if I have no control over the server (admins won’t change it to use dynamic compression), but I can supply an HTML file that is already gzipped. How could I access that file so that the unzipping happens in the background simply by accessing it? Thanks.

Hi Hector, one strategy would be to use PHP, if it’s allowed on the server. Rename your .html file to .php and add the PHP code in the article to the top of the file (see “Setting up the server” section).

If you can’t use PHP and must use straight HTML, I don’t know a way to compress the content without changing server settings.

Hmmm… great !! u’r the ONE man !!

[…] How To Optimize Your Site With GZIP Compression […]

Just wanted to say, I rarely comment on websites, but your site is a lot of fun to read. I am considering starting a new site from the ground up to replace my abandoned blog, so this is pretty interesting stuff.

Thanks Shook, I had a lot of fun writing the articles too and I’m glad you enjoyed them too. Good luck with your blog! :slight_smile:

[…] How To Optimize Your Site With GZIP Compression […]