Can I use mod_deflate to compress files on the fly?

We have the Apache mod_deflate module available on our servers, but we don't have it set to compress files by default.

That's mostly because the extra CPU usage required to compress small files can sometimes slow down a page more than the lowered bandwidth speeds it up. (This has become more true over time, as Internet users tend to have faster connections nowadays.)

However, if you have larger HTML, CSS or JavaScript files (bigger than, say, 20 KB on average), it can make sense to compress them on the fly.

The mod_deflate documentation explains how to enable and configure it, but the simplest setting is to add this to your .htaccess file as a single line:

AddOutputFilterByType DEFLATE text/html text/css application/javascript

What if I'm using WordPress?

The WP Super Cache plugin we recommend can compress cached files when they're created. This speeds things up even more: in most cases, the HTML pages will already be compressed, and mod_deflate won't have to do any work at all.

So if you're using WordPress, you should enable the "Super Cache Compression" feature (in addition to following the above instructions). That gives you the best of both worlds.