[…] 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. […]
[…] 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. […]
Anyway, I found this topic when using CURL to download pages. This library supports compress natively. Just enable it like this :
curl_setopt($ch,CURLOPT_ENCODING,“gzip,deflate”);
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
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)$”.
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.
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.