Gzip vs. Brotli: Compression Comparison

Gzip and Brotli are two popular compression methods for improving website speed and reducing file sizes. Here’s what you need to know:

  • Gzip: Released in 1992, it’s widely supported and works best for dynamic content. It’s faster but offers slightly lower compression rates.
  • Brotli: Launched in 2015, it achieves better compression (15–25% smaller files than Gzip) but is slower and uses more resources. It’s ideal for static files and modern browsers.

Quick Comparison

Feature Gzip Brotli
Release Year 1992 2015
Compression Levels 1-9 1-11
Best For Dynamic content Static assets
Compression Speed Faster Slower
File Size Reduction 50–70% smaller 15–25% smaller than Gzip
Browser Support All browsers Modern browsers only
Resource Usage Lower CPU/memory Higher CPU/memory

Key takeaway: Use Gzip for dynamic content and older browsers. Opt for Brotli for static assets and modern browsers to maximize performance. Many servers combine both for optimal results.

How File Compression Increases Your Website Speed: BROTLI vs GZIP Algorithms

How Gzip Works

Gzip plays a key role in improving site speed. Here’s a look at how it works behind the scenes. It compresses files using two techniques: LZ77 and Huffman coding.

Gzip Compression Process

The process starts with LZ77, which spots repeated strings and replaces them with references. Then, Huffman coding steps in to assign shorter codes to frequently occurring characters.

Gzip offers compression levels ranging from 1 to 9, each balancing speed and compression ratio differently:

Level Speed Compression Ratio Best Used For
1-3 Very Fast 2.5x – 3x Real-time compression
4-6 Moderate 3x – 3.5x General web content
7-9 Slow 3.5x – 4x Static file optimization

For example, compressing a 100KB JavaScript file produces these results:

  • Level 3: ~35KB (65% smaller)
  • Level 6: ~30KB (70% smaller)
  • Level 9: ~27KB (73% smaller)

While Gzip is highly effective, it does come with some trade-offs.

Gzip Strengths and Weaknesses

Strengths:

  • Works seamlessly with all major browsers.
  • Compresses text-based files like HTML, CSS, and JavaScript efficiently.
  • Low CPU usage at lower compression levels.
  • Decompresses files quickly, regardless of the compression level.
  • Supported natively by most web servers, including Apache and Nginx.

Weaknesses:

  • Doesn’t compress already-compressed files (e.g., images, PDFs) well.
  • Higher compression levels (7-9) can strain CPU resources.
  • Lacks a pre-defined dictionary tailored for web content.
  • Falls short in compression ratio compared to newer algorithms.
  • Uses a single-threaded process, which limits performance.

The trade-offs become clear with larger files. For instance, compressing a 1MB JavaScript bundle takes:

  • ~50ms at Level 3
  • ~120ms at Level 6
  • ~300ms at Level 9

Because of this balance, most web servers favor Level 6, which offers solid compression without overloading the server.

How Brotli Works

Brotli takes a different approach compared to Gzip by using a pre-defined static dictionary along with standard algorithms, resulting in efficient compression.

Brotli Compression Process

Brotli offers adjustable levels to balance speed and compression quality. Lower levels focus on faster processing, ideal for dynamic content, while higher levels achieve better compression for static files.

The process involves scanning input with Brotli’s built-in dictionary, refining data through context modeling, and encoding it using advanced Huffman coding. This method often results in files that are 15–25% smaller than those compressed with Gzip. Brotli’s ability to handle both dynamic and static content effectively makes it a compelling option for web performance.

Brotli Strengths and Weaknesses

Strengths:

  • Provides excellent compression for HTML, CSS, JavaScript, and web fonts.
  • Utilizes a pre-built dictionary to optimize compression for common web assets.
  • Performs especially well with text-based content.

Weaknesses:

  • Consumes more memory compared to Gzip.
  • Slower compression speeds at higher levels.
  • Lacks support in older browsers like Internet Explorer 11 and earlier.
  • Less widely implemented on servers compared to Gzip.
  • Demands more resources during maximum compression.

Many content delivery networks (CDNs) and web servers opt for lower Brotli levels for dynamic content to prioritize speed, while reserving higher levels for static files where compression costs are spread across multiple requests. These traits show how Brotli can outperform Gzip in specific scenarios.

sbb-itb-608da6a

Gzip vs. Brotli Performance Tests

Tests highlight noticeable differences in how Gzip and Brotli perform across various file types and scenarios.

File Size Reduction Results

Brotli outperforms Gzip in compression ratios, especially at its highest settings. For web assets like HTML, JavaScript, CSS, web fonts, and JSON, Brotli’s efficiency results in smaller file sizes. However, achieving these smaller sizes involves considering the time needed for compression.

Compression Time Analysis

Brotli’s better compression comes with longer processing times compared to Gzip. This makes Brotli’s higher compression levels more practical for files compressed once, such as static assets, rather than for content generated dynamically. For dynamic content, Gzip remains the faster and more suitable option.

Browser Compatibility Guide

Both Gzip and Brotli are supported by modern browsers. Gzip works with virtually all browser versions, while Brotli is supported in newer versions of Chrome, Firefox, Safari, Edge, and Opera. To balance performance and compatibility, many web servers use content negotiation: serving Brotli-compressed files to browsers that support it and defaulting to Gzip for older clients. This ensures optimal performance without leaving any users behind.

Choosing and Setting Up Compression

When to Use Gzip

Gzip works best for dynamic content that needs to be compressed in real time. Common examples include:

  • User dashboards
  • Real-time analytics
  • Cart data
  • Personalized feeds

Its fast processing speed makes it a great choice for high-traffic websites that compress content on-the-fly. Plus, Gzip is supported by all major browsers and works well with older systems.

When to Use Brotli

Brotli is better suited for static assets because it achieves higher compression rates. It’s ideal for compressing:

  • HTML
  • JavaScript
  • CSS
  • Web fonts
  • SVG graphics
  • JSON data

For CDNs that serve static files, Brotli’s efficiency helps cut bandwidth usage and speed up loading times. Make sure your server is set up to take advantage of these benefits.

Setup Instructions

Follow these steps to configure your server for compression:

Server Configuration

Apache (.htaccess)

# Enable Brotli compression  
AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/json application/xml

# Enable Gzip for browsers without Brotli support  
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript application/json application/xml

Nginx (nginx.conf)

# Brotli Settings  
brotli on;  
brotli_comp_level 6;  
brotli_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

# Gzip Settings  
gzip on;  
gzip_vary on;  
gzip_comp_level 6;  
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

Recommended Compression Levels

Compression Type Static Content Dynamic Content
Brotli Level 11 (max) Level 4-6
Gzip Level 6-7 Level 4-5

Professional Website Management Options

Managing compression effectively requires a solid technical background, making professional services a smart choice for setting up and maintaining both Gzip and Brotli.

OneNine Compression Services

OneNine

OneNine combines AWS hosting with CloudFront CDN to boost performance across various content types. Their approach includes monitoring and fine-tuning compression settings through dedicated infrastructure and ongoing adjustments.

The benefits of expert management speak for themselves. Ernest Chapman shares his experience:

"After OneNine took over one of my client’s website portfolios, we’ve seen each site’s speed increase by over 700%. Load times are now around a second."

Key features of their service include:

Feature What It Does
AWS Dedicated Hosting Provides reliable power for compression tasks
CloudFront CDN Integration Speeds up delivery from edge locations
Daily Performance Monitoring Keeps compression settings in check
Automatic Re-optimization Avoids any drop in performance

These tools work together to ensure your website stays fast and efficient. Greg Moore highlights the value of their ongoing support:

"OneNine is extremely helpful in providing on-going implementation and tech support."

This hands-on approach keeps load times quick and makes the most of your bandwidth.

Conclusion

Key Differences

Gzip and Brotli stand apart in several ways:

Feature Gzip Brotli
File Size Reduction Shrinks file sizes by 50–70% Reduces file sizes an extra 15–25% compared to Gzip
Compression Speed Faster compression Slower compression
Browser Support Works with nearly all browsers Primarily supported by modern browsers
Resource Usage Uses less CPU and memory Requires more CPU and memory
Best For Dynamic content and real-time compression Static assets with pre-compression

Making Your Choice

These differences can shape your approach to compression:

  • Go with Gzip if you need:

    • Quick, lightweight compression for dynamic content
    • Compatibility with a wide range of browsers
    • A straightforward setup without major system changes
  • Opt for Brotli when you have:

    • Static assets that can be pre-compressed
    • Users primarily on modern browsers
    • Adequate server resources to handle higher demands
    • CDN support for better integration

A smart strategy is to use Brotli for static files and Gzip for dynamic content or older browsers. This way, you get the best compression results while maintaining broad accessibility.

Related Blog Posts

Design. Development. Management.


When you want the best, you need specialists.

Book Consult
To top