Brotli Compression: A Fast Alternative to GZIP Compression

An illustration of small figures measuring a massive folder with a tape measure.

Speed is important for any website. In the web’s pursuit of fast loading times, we have a number of different technologies to help us. One approach is to minimize the underlying code your site will use without affecting how it functions. GZIP compression is one way to do this, but Brotli compression is an alternative fledgling method that commands attention.

It’s a Google-developed solution that looks to provide a number of benefits over (as well as an alternative to) GZIP compression. The details in this article will go into exactly what the technology offers, but Brotli compression is fast and efficient — which ticks all the boxes you need to investigate it.

For this tutorial, we’re going to look into Brotli compression and show you how to check whether your site uses it, and how to enable it if you need to. First, we’re going to place Brotli within the compression algorithm space, and talk about why you’d want to use it over other solutions.

Data Compression for the Web

In its most basic form, data compression takes the code for a website or app, and minimizes the file size. This gives you lighter files to move around the web and reduces the time it takes to load and render a website. You’ll find there are lots of ways to compress the data depending on the file type you’re working with.

A common approach is “minification.” This is where an algorithm strips your site’s code of some of its superfluous elements. The idea is that aspects such as indents, comments, whitespace, and more will increase file sizes, and therefore loading times.

Ready to look into Brotli compression and see how to enable it on your own site? 💪 The answers are here 💥Click to Tweet

Removing these elements doesn’t affect the user experience (UX) in most situations. However, it does make things more straightforward for the computers that have to compile and render the code. For example, take this suite of code:

define( 'WP_INSTALLING', true );

/** Sets up the WordPress Environment. */
require __DIR__ . '/wp-load.php';
require __DIR__ . '/wp-blog-header.php';
if ( ! is_multisite() ) {
  wp_redirect( wp_registration_url() );
  die();
}

$valid_error_codes = array( 'already_active', 'blog_taken' );

The above code uses elements like spaces and carriage returns to make it human-readable, but a computer doesn’t need these to understand the core code. What’s more, these batches of whitespace and line breaks will take up precious room that, removed, can give you a performance boost.

If you minimize this code, it looks completely different:

define( 'WP_INSTALLING', true ); /** Sets up the WordPress Environment. *
/ require __DIR__ . '/wp-load.php';
require __DIR__ . '/wp-blog-header.php';
if ( ! is_multisite() ) {
  wp_redirect( wp_registration_url() );
  die();
}

$valid_error_codes

[…]

 



This article was written by Salman Ravoof and originally published on Blog – Kinsta®.

Disclosure: Some of the links in this post are "affiliate links." This means if you click on the link and purchase the product, We may receive an affiliate commission.

Leave a Comment

You have to agree to the comment policy.

Show Your ❤️ Love! Like Us
Scroll to Top