Hosting Hosting Features Spanish version

Support article

Gzip and Brotli Compression: How to Enable Them on Your Website

Enable Gzip or Brotli compression on your website to reduce HTML, CSS and JS size by up to 80%. More speed without losing quality.

Published: 12/07/2026 Updated: 12/07/2026

Introduction

Gzip compression and Brotli are two technologies that reduce the size of your website’s text files (HTML, CSS, JavaScript) before sending them to the browser. The result: your website weighs less, loads faster and consumes less bandwidth, without losing any quality.

It’s one of the easiest and most impactful optimizations. In this article you’ll see what they are, which is better, and how to enable them.

What text compression is and what it’s for

Your website’s files are largely text: the pages’ HTML, the CSS files that style them, the JavaScript files that add functionality. This text can be compressed, just like you compress a file into ZIP to take up less space.

Compression works like this:

  1. The server compresses the file before sending it.
  2. The visitor’s browser receives it compressed.
  3. The browser decompresses it and displays it.

For the user, everything is transparent: they notice nothing. But the file travels much faster over the network because it weighs less.

[Imagen sugerida: diagram of how Gzip/Brotli compression works]

Compression can reduce the size of text files by 70% to 80%. That is, a 100 KB CSS file becomes 20-30 KB.

Gzip vs Brotli: which is better?

Both technologies do the same thing, but Brotli is more modern and efficient.

FeatureGzipBrotli
Year created19922013
CompressionGoodBetter (15-25% more than Gzip)
Browser supportAllAll modern
Compression speedFastA bit slower
RecommendationVery goodBetter if available

Conclusion: if your server supports Brotli, use it. If not, use Gzip. Both are huge improvements over not compressing at all.

All modern browsers (Chrome, Firefox, Safari, Edge) support both Gzip and Brotli. You don’t have to worry about compatibility.

How to check if your website already has compression

Before enabling it, check if you already have it (many hosts enable it by default).

Method 1: PageSpeed Insights

  1. Go to pagespeed.web.dev.
  2. Analyze your website.
  3. If you see the “Enable text compression” warning, you don’t have it active.

[Imagen sugerida: screenshot of PageSpeed showing the text compression warning]

Method 2: Online tool

  1. Go to checkgzipcompression.com.
  2. Type your URL.
  3. It will tell you if you have Gzip active and how much it saves.

How to enable compression in Apache (cPanel)

If you use Apache (most shared hosting), it’s enabled by editing the .htaccess file.

For Gzip

Add these lines at the top of your .htaccess:

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/json
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

For Brotli

If your server supports Brotli:

<IfModule mod_brotli.c>
  AddOutputFilterByType BROTLI_COMPRESS text/html
  AddOutputFilterByType BROTLI_COMPRESS text/css
  AddOutputFilterByType BROTLI_COMPRESS text/javascript
  AddOutputFilterByType BROTLI_COMPRESS application/javascript
  AddOutputFilterByType BROTLI_COMPRESS application/json
  AddOutputFilterByType BROTLI_COMPRESS application/xml
  AddOutputFilterByType BROTLI_COMPRESS image/svg+xml
</IfModule>

At miHosting, LiteSpeed servers enable compression by default. If you don’t have it, open a ticket and we’ll help you enable it.

How to enable compression in Nginx

If you use Nginx (common on VPS), it’s configured in the nginx.conf file.

For Gzip

gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;
gzip_min_length 1000;
gzip_comp_level 6;

For Brotli

If the Brotli module is installed:

brotli on;
brotli_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;
brotli_comp_level 6;

Restart Nginx after changes:

systemctl restart nginx

How to enable compression in WordPress

In WordPress, the easiest way is with an optimization plugin:

  • LiteSpeed Cache: if your host uses LiteSpeed, compression is active by default.
  • WP Rocket: includes Gzip activation in its configuration.
  • W3 Total Cache: allows enabling Gzip/Brotli.

If you don’t use a plugin and your host is Apache, you can edit .htaccess directly from cPanel → File Manager.

Which files you should NOT compress

Text compression is for HTML, CSS, JS, JSON, XML and SVG. Do not compress:

  • JPEG, PNG, WebP images: already compressed. Compressing them again doesn’t reduce weight and wastes resources.
  • Video and audio (MP4, MP3): same, already compressed.
  • PDF: already compressed.
  • Fonts (WOFF, WOFF2): already compressed.

Compressing these files provides nothing and can even slow down the server.

Useful tips

  • Enable Brotli if available. It compresses better than Gzip.
  • Check before editing .htaccess. An error in .htaccess can break your entire website. Back up first.
  • Don’t compress images or videos. Only text files.
  • Measure before and after. Check with PageSpeed or GTmetrix to see the real savings.
  • Combine with minification. Compression reduces file size; minification reduces content. Together, savings are maximized.

Common problems

I added the code but PageSpeed still warns

Check that the .htaccess has been saved correctly and that there’s no other .htaccess in a parent folder overriding it. It may also be cache: wait a while and try again.

My website breaks after editing .htaccess

There’s a syntax error. Restore the previous .htaccess from the backup and try again carefully.

I don’t have access to .htaccess or server configuration

In that case, use a WordPress plugin (like WP Rocket or W3 Total Cache) that enables compression for you.

Brotli isn’t available on my host

Not all hosts support it yet. If you don’t have it, Gzip is perfectly valid. Ask us if we can enable it for you.

Compression works, but the website is still slow

Compression is one of several optimizations. Also review cache, images and plugins. And make sure your host has good response time (TTFB).

Frequently asked questions

Does compression affect my website’s quality?

No. Text compression doesn’t lose quality. The decompressed file is identical to the original.

Gzip or Brotli?

Brotli if available, because it compresses better. If not, Gzip, which works perfectly.

Does my host include compression by default?

Quality hosts (like miHosting’s with LiteSpeed) enable it by default. If you don’t have it, it can be enabled.

Can I use Gzip and Brotli at the same time?

Yes, the server negotiates with the browser which to use. If the browser supports Brotli, Brotli is used; if not, Gzip is used.

Does compression consume server resources?

Very few. Modern compression is efficient and the bandwidth savings more than compensate for the small CPU cost.

Enable compression and fly

Gzip or Brotli compression is one of the most profitable optimizations: enabling it takes five minutes and reduces your website’s weight by up to 80%. It’s one of the first things Google recommends in PageSpeed Insights.

If you need help enabling it, at miHosting our technicians can configure compression for you. On LiteSpeed plans, compression is already active by default. Open a ticket from your client panel and we’ll help.