When it comes to compression on the web, GZIP reigns supreme. In the 18 years since GZIP was first supported by browsers, other compression methods have been introduced but none have matched GZIP's combination of speed, support and results.

Brotli, the compression algorithm Google released as open-source back in September, may soon change that. Chrome (version 49, due in early to mid March) will be shipping with Brotli support, and Firefox (version 44) already has it. Particularly given Chrome's significant reach on the Android platform, this means that Brotli support will go from zero to sixty in no time--bringing reduced file sizes along with it.

To get a better understanding of just how big those savings could be, and what the trade-offs are, we ran a few independent experiments.

Testing the Top 1000 URL's According to HTTP Archive

For the first set we took a list of the top 1000 URL's on the web (pulling the list from HTTP Archive) and downloaded the HTML for each page, as well as all JavaScript and CSS assets. For each asset, we recorded the original weight. We then recorded the weight of the asset with GZIP applied, as well as the weight of the asset with Brotli applied. We kept the quality level of each to the default provided on each tool. We did not unminify any assets, but we did uncompress those who were pre-compressed with GZIP.

HTML

Median GZIP Savings 78% Median Brotli Savings 82% Brotli Improvement over GZIP, Median 21% Brotli Improvement over GZIP, 90th percentile 39%

Javascript

Median GZIP Savings 63% Median Brotli Savings 68% Brotli Improvement over GZIP, Median 14% Brotli Improvement over GZIP, 90th percentile 26%

CSS

Median GZIP Savings 79% Median Brotli Savings 82% Brotli Improvement over GZIP, Median 17% Brotli Improvement over GZIP, 90th percentile 27%

The results are really promising! All three types of resources--HTML, JS and CSS--saw significant savings from using Brotli instead of GZIP.

NOT SO FAST

We can't judge a compression algorithm purely by the amount of bytes saved, however. If we could, GZIP would've been dethroned long ago. Another major consideration is the compression speed: how long does it take to perform the actual compression.

There's a fair amount of chatter about Brotli being much slower than GZIP. And on the surface it is. Run a benchmark on your machine using the default settings of GZIP versus the default settings of Brotli and you'll see the Brotli is much, much slower.

But the key phrase there is "default settings".

GZIP has nine quality levels. If you run GZIP using a quality setting of "1", you won't get a lot of file savings, but the compression will occur incredibly quickly. If you run GZIP using a quality setting of "9", you'll maximize your file savings, but the process will be quite slow. GZIP uses a default setting of "6": it provides a nice blend of file savings and compression speeds.

Brotli has eleven quality levels. Just like GZIP, a quality of "1" is very fast but less effective, whereas a quality setting of "11" is very slow but provides big savings in file size. While GZIP's default setting has been chosen to provide a balance of speed and compression; Brotli's default setting has not. Out of the box Brotli runs on a setting of "11" meaning you get a huge savings in data, but a much slower compression speed.

By playing around with the quality setting on Brotli, you can find a much safer balance.

To get a better idea of where that magic setting is, we looked at the HTML for the top 1000 sites.

We compressed each file individually at different settings of Brotli and GZIP to see what the results would be. For each setting, we ran the compression 20 times and recorded the median speed. The tests were run on a MacBook Air to make it easier to see the impact the settings had on the compression rate. These compression speeds are going to be slower than if you ran them on a more powerful machine. The results (sorted by throughput) are below.

We've highlighted GZIP's default settings in bold, as well as the Brotli setting that had a comparable speed.

Compression Method Savings Throughput, Median Difference in Speed from GZIP Default Difference in Size from GZIP Default GZIP (1)