Sitemap
Bits and Pieces

Insightful articles, step-by-step tutorials, and the latest news on full-stack composable software development

Follow publication

Will Brotli Replace Gzip?

6 min readOct 21, 2020

--

Zoom image will be displayed

What is Brotli?

Zoom image will be displayed
Example: exploring reusable React components shared on Bit.dev

Is Brotli Better than Gzip?

According to research by CertSimple, Brotli compresses JavaScript files 14% smaller than Gzip, while HTML and CSS compression rates are 21% and 17% better than Gzip, respectively.

Enabling Brotli & Gzip Compression with a CDN

Step 1: Create an S3 Bucket and Upload the React Bundle

Step 2: Create an AWS CloudFront Distribution

Zoom image will be displayed
Screenshot by Author: Create Distribution Window

Step 3: Set Cache Policy to Brotli

Zoom image will be displayed
Creating a new Cache policy

Step 4: Verify the Compression Results

Zoom image will be displayed
Response Header with Brotli Enabled

Uncompressed vs. Gzip Vs.Brotli

JavaScript File Performance

Zoom image will be displayed
File Size Comparison

The uncompressed main.js file size was 319kB while Gzipped and Brotli versions were 89.3kB and 81.7kB. Gzipped version has reduced its file size 3.5 times while the Brotli compression version has reduced 3.9 times.

Zoom image will be displayed
Loading Time Comparison

Gzip took 966ms to load the file while Brotli took only 296ms, which is remarkable. The uncompressed version took 1.9 seconds to load the JS file.

JSON Payload Performance

Zoom image will be displayed
Zoom image will be displayed
Loading Time & File Size of XHR

As you can see, Brotli leads the competition with 1.34 seconds load time and 224B file size while Gzip falls behind with 1.54 seconds and 318B.

In this case, the original file size was 419B, and the compression ratio of Brotli is around 46%, while Gzips’ ratio is about 24%.

Conclusion

--

--

Bits and Pieces
Bits and Pieces
Chameera Dulanga
Chameera Dulanga

Responses (4)