Best Web Server Compression using Zopfli

Zopfli is a free, open-source program from Google written in C that aims to increase the compression ratio of files, which when implemented correctly can significantly improve web server and network performance.

Visit the Zopfli GitHub page at https://github.com/google/zopfli

Description

Zopfli Compression Algorithm is a new zlib (gzip, deflate) compatible compressor. This compressor takes more time (~100x slower), but compresses around 5% better than zlib and better than any other zlib-compatible compressor we have found.

Zopfli is not intended to replace traditional compression programs. As mentioned above, it is much, much slower to process, and intentionally trades compute time for a smaller file.

How can I use Zopfli to speed up my web server?

The suggested use here is that you can pre-compress web files ahead of time so your server (Apache, Nginx, etc.) does not have to do compression on demand. Your web server will be configured to look for a pre-compressed version of your web file, and serve that instead.

Other Benefits

Another benefit to pre-compress web files is that your web server will know the length of the compressed file, and will be able to include the byte length of the file inside the HTTP header.

How to Install

Instructions on how to install Zopfli on Linux

cd ~
git clone https://github.com/google/zopfli.git
cd zopfli
make
chmod +x zopfli
cp zopfli /usr/local/bin/
					

Integrate Zopfli with WinSCP

Here's a trick for WinSCP users. Here is how you can add a 'Right-click' menu option to precompress a file as Zopfli .gz

  1. Go to View | Preferences
  2. Near the bottom select Commands
  3. Click the Add... button and in the Description field type Precompress as gzip with Zopfli
  4. In the Custom command field type zopfli "!" && touch -am -c -r "!" "!".gz