Check 06.08 · Performance and Core Web Vitals

Enable Brotli/Gzip

Enable Brotli or Gzip compression of text files on Apache, Nginx, Cloudflare, AWS, Plesk, cPanel or WordPress, then check that it works.

Priority
Important
Difficulty
Easy
Estimated time
15 to 30 min
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

HTTP compression reduces the size of text files (HTML, CSS, JavaScript, JSON, SVG) before they are sent to the browser. Brotli compresses better than Gzip and every current browser supports it over HTTPS; Gzip remains the universal fallback. Once this check is done, every text response from the site carries a Content-Encoding: br or Content-Encoding: gzip header.

Why it matters

With each request, the browser announces the algorithms it can decode in the Accept-Encoding header. If the server does not compress, it sends the raw file: an HTML page or a stylesheet then commonly weighs three to five times more on the network than necessary.

This extra weight is paid mostly on mobile and slow connections, where downloading the HTML, CSS and JavaScript directly delays rendering. Crawlers pay for it too: Googlebot announces support for gzip, deflate and Brotli, and therefore downloads fewer bytes per page when compression is active.

Compression does not change the content: the browser decompresses it and gets exactly the same file. It is one of the lowest-risk and quickest optimizations to put in place.

What it improves

  • Load time Fewer bytes to transfer for HTML, CSS and JavaScript, so a faster first render and LCP (Largest Contentful Paint, rendering of the largest visible element), especially on mobile networks.
  • Lighthouse audit The “Enable text compression” warning disappears.
  • Crawling Crawlers use less bandwidth per page. The effect on crawl budget is only noticeable on very large sites.
  • Costs Less bandwidth billed by the host or the CDN (Content Delivery Network).
  • Rankings No direct effect. Compression is not a ranking factor; it contributes to Core Web Vitals, which are one among many others.

How to check

Request the home page while announcing support for Brotli and Gzip, then read the response headers:

curl -s -o /dev/null -D - -H "Accept-Encoding: br, gzip" https://example.com/ | grep -i -E "content-encoding|vary"

Compliant result:

content-encoding: br
vary: Accept-Encoding

content-encoding: gzip is acceptable. No content-encoding line means the response is sent uncompressed.

Repeat the test on a CSS file and a JavaScript file: sometimes the HTML is compressed by the application but not the static files, or the other way round.

To measure the gain, compare the transferred size with and without compression:

curl -s -o /dev/null -w "%{size_download} bytes\n" https://example.com/
curl -s -o /dev/null -w "%{size_download} bytes\n" -H "Accept-Encoding: br, gzip" https://example.com/

Other ways:

Good to know: if the site goes through a CDN, you are testing the CDN's response. To test the origin server, query it directly: curl --resolve example.com:443:ADRESSE_IP_ORIGINE ….

How to implement

Before you start

Three rules apply to every environment:

  • Compress text formats: HTML, CSS, JavaScript, JSON, XML, RSS feeds, SVG, manifests, TTF and OTF fonts.
  • Do not compress what is already compressed: JPEG, PNG, WebP, AVIF, videos, archives, WOFF and WOFF2 fonts. You would spend CPU for no gain.
  • One layer is enough: if a CDN compresses at the edge, still keep compression on the origin to speed up the origin-to-CDN leg, but do not compress a third time in the application.

Recommended levels for on-the-fly compression: Brotli 4 to 6, Gzip 5 to 6. Maximum levels (Brotli 11, Gzip 9) are only worthwhile for files precompressed at build time.

Apache

Versions Apache 2.4.26 and later (2.4.x).

Enable the mod_brotli (Apache 2.4.26 and later) and mod_deflate modules:

sudo a2enmod brotli deflate

On Red Hat family distributions, check that the LoadModule brotli_module and LoadModule deflate_module lines are present in /etc/httpd/conf.modules.d/.

Then add this block to the server or virtual host configuration, or to the .htaccess file at the root of the site:

<IfModule mod_brotli.c>
    AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/css text/xml
    AddOutputFilterByType BROTLI_COMPRESS application/javascript application/json application/xml
    AddOutputFilterByType BROTLI_COMPRESS application/rss+xml application/atom+xml application/manifest+json
    AddOutputFilterByType BROTLI_COMPRESS image/svg+xml font/ttf font/otf
    BrotliCompressionQuality 5
</IfModule>

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
    AddOutputFilterByType DEFLATE application/javascript application/json application/xml
    AddOutputFilterByType DEFLATE application/rss+xml application/atom+xml application/manifest+json
    AddOutputFilterByType DEFLATE image/svg+xml font/ttf font/otf
</IfModule>

BrotliCompressionQuality can only be set in the server or virtual host configuration: remove this line if you use .htaccess. Apache serves Brotli to browsers that accept it and Gzip to the others.

Test, then reload:

sudo apachectl configtest && sudo systemctl reload apache2

Nginx

Versions Nginx 1.18 and later, including 1.30 (stable) and 1.31 (mainline); ngx_brotli module 1.0.0rc.

Gzip is built in. Add this block to the http context of /etc/nginx/nginx.conf or to a /etc/nginx/conf.d/compression.conf file:

gzip on;
gzip_comp_level 5;
gzip_min_length 1024;
gzip_proxied any;
gzip_vary on;
gzip_types
    text/plain text/css text/xml
    application/javascript application/json application/xml
    application/rss+xml application/atom+xml application/manifest+json
    image/svg+xml font/ttf font/otf;

Do not list text/html: Nginx always compresses it and would report a duplicate.

Brotli is not included in Nginx: it requires the ngx_brotli module. On Debian 12 and later and on Ubuntu 24.04 and later, it is available as packages (not on Ubuntu 22.04, where you have to compile the module):

sudo apt install libnginx-mod-http-brotli-filter libnginx-mod-http-brotli-static

Then, in the same http context:

brotli on;
brotli_comp_level 5;
brotli_min_length 1024;
brotli_types
    text/plain text/css text/xml
    application/javascript application/json application/xml
    application/rss+xml application/atom+xml application/manifest+json
    image/svg+xml font/ttf font/otf;

If your build produces .br and .gz files, add brotli_static on; and gzip_static on; to serve them directly without recompressing.

sudo nginx -t && sudo systemctl reload nginx

LiteSpeed

Versions LiteSpeed Web Server 6.x, OpenLiteSpeed 1.7 and later.

Compression is on by default on LiteSpeed Web Server and OpenLiteSpeed. To check or adjust it: WebAdmin console, Server Configuration > Tuning, section dedicated to Gzip and Brotli compression. Check that compression and dynamic compression are enabled and that text MIME types are in the list of compressible types, then perform a graceful restart.

LiteSpeed Enterprise also reads mod_deflate directives from an .htaccess file: the block from the Apache section works as is on LiteSpeed hosting.

Caddy

Versions Caddy 2.

Add the encode directive to the site block in the Caddyfile:

example.com {
    encode zstd gzip
    root * /var/www/example
    file_server
}

Caddy does not compress with Brotli on the fly in its standard version, but it can serve precompressed files:

file_server {
    precompressed br zstd gzip
}

Reload with sudo systemctl reload caddy.

IIS

Versions IIS 10 (Windows Server 2016 to 2025), IIS Compression extension 1.0.

Install the “Static Content Compression” and “Dynamic Content Compression” features (Server Manager, Web Server role, Performance section), then enable them in the site's web.config:

<configuration>
  <system.webServer>
    <urlCompression doStaticCompression="true" doDynamicCompression="true" />
  </system.webServer>
</configuration>

For Brotli, install Microsoft's official IIS Compression extension, which adds optimized br and gzip providers. Restart the site from IIS Manager.

Cloudflare

Versions Cloudflare dashboard, all plans, November 2026.

Cloudflare automatically compresses text responses for visitors at the edge, according to what the browser accepts: there is nothing to enable on a site that is already proxied (orange cloud in the DNS tab). The default algorithm depends on the plan: Zstandard on Free, Brotli on Pro and Business, Gzip on Enterprise; the encoding served also depends on what the browser announces in Accept-Encoding.

Points to check:

  • Content type: Cloudflare only compresses certain MIME types. A JavaScript file served by the origin as application/octet-stream will not be compressed. Fix the Content-Type header at the origin.
  • Cache-Control: no-transform: this header forbids Cloudflare from modifying the response, and therefore from compressing it. Remove it if it is not intended.
  • Compression rules: Rules > Overview (rules overview), then creating a compression rule, lets you choose the algorithm (Gzip, Brotli, Zstandard) by URL or file type. They are available on all plans; only the number of rules changes (10 on Free, 25 on Pro, 50 on Business).
  • Origin: keep compression active on your server. Cloudflare accepts compressed responses from the origin, which speeds up the origin-to-Cloudflare leg.

After a change at the origin, purge the cache: Caching > Configuration, then “Purge Everything”.

AWS

Versions CloudFront, S3, Elastic Load Balancing and Amplify Hosting consoles, November 2026.

CloudFront compresses at the edge if two settings are combined:

  1. In the CloudFront console, open the distribution, Behaviors tab, edit the behavior and set “Compress objects automatically” to Yes.
  2. Use a cache policy that enables Gzip and Brotli. The managed CachingOptimized policy does; in a custom policy, check both encodings.

CloudFront only compresses the MIME types on its list, for objects from 1,000 bytes to 10 MB, and only if the origin sends a Content-Length header. Objects already in the cache are not recompressed: run an invalidation (/*) after the change.

S3 compresses nothing on the fly. Put CloudFront in front of the bucket, or upload precompressed files with the appropriate Content-Encoding metadata.

Application Load Balancer does not compress either: enable compression on the instances' web server (see Apache or Nginx) or on CloudFront.

Amplify Hosting compresses automatically.

Google Cloud

Versions Cloud CDN with external Application Load Balancer, Firebase Hosting, gcloud CLI, November 2026.

On an external Application Load Balancer with Cloud CDN, enable dynamic compression on the backend service:

gcloud compute backend-services update NOM_DU_SERVICE --global --compression-mode=AUTOMATIC

Firebase Hosting, and Cloud Run behind Firebase Hosting, compress automatically.

Azure

Versions Azure Front Door Standard and Premium, App Service, November 2026.

On Azure Front Door, open the route concerned and check “Enable compression”. On App Service for Windows, IIS compression applies (see IIS); on Linux, configure it in the application's server or put Front Door in front.

Varnish

Versions Varnish Cache 7.x to 9.x (VCL 4.1).

Varnish handles Gzip but not Brotli. Ask it to compress what the backend sends uncompressed, in vcl_backend_response:

sub vcl_backend_response {
    if (beresp.http.Content-Type ~ "text|javascript|json|xml|svg") {
        set beresp.do_gzip = true;
    }
}

To serve Brotli, put a server or CDN that handles it in front of Varnish.

Plesk

Versions Plesk Obsidian 18.0 for Linux.

On Plesk for Linux, Nginx sits in front of Apache. Open Websites & Domains > your domain > Apache & nginx Settings (Plesk documentation), then paste into “Additional nginx directives”:

gzip on;
gzip_comp_level 5;
gzip_min_length 1024;
gzip_proxied any;
gzip_vary on;
gzip_types text/plain text/css text/xml application/javascript application/json application/xml application/rss+xml image/svg+xml font/ttf font/otf;

Confirm: Plesk tests and reloads the configuration. Recent versions of Plesk Obsidian also ship a Brotli module for Nginx, which the server administrator enables from the command line; see the Plesk documentation for your version. If Nginx is disabled on the server, use the .htaccess block from the Apache section.

cPanel

Versions cPanel & WHM 110 and later, Jupiter theme.

In cPanel, Software section, open “Optimize Website” and choose “Compress All Content” or the list of MIME types from the Apache section. cPanel writes the mod_deflate directives to your account's .htaccess.

If the tool does not appear, paste the block from the Apache section into public_html/.htaccess yourself. Brotli requires the host to have installed mod_brotli in EasyApache 4 from WHM.

Shared hosting

With OVHcloud, o2switch, Infomaniak, Ionos or Hostinger, Gzip compression is usually already active. If the test in the “How to check” section shows no content-encoding, paste the block from the Apache section into the .htaccess at the root of the site: the <IfModule> blocks prevent any error if a module is missing. Brotli depends on the host; going through Cloudflare provides it without changing anything on the server.

Vercel

Versions Vercel, all plans, November 2026.

Automatic. Vercel compresses with Brotli or Gzip depending on the browser, with no configuration.

Netlify

Versions Netlify, all plans, November 2026.

Automatic, no configuration needed.

WordPress

Versions WordPress 6.4 and later (checked on 7.1), caching plugins in their November 2026 versions.

WordPress compresses nothing itself: the server or the CDN takes care of it. Start with the test in the “How to check” section.

  • Apache or LiteSpeed server: most caching plugins (WP Rocket, W3 Total Cache, WP Fastest Cache) add Gzip rules to .htaccess on activation. LiteSpeed Cache relies on the server's compression.
  • Nginx server: plugins cannot modify the configuration; apply the Nginx section or ask your host.
  • Managed WordPress hosts (Kinsta, WP Engine, WordPress.com): compression already active.

Shopify

Versions Shopify, all plans, November 2026 (likewise for Wix, Squarespace and Webflow).

Automatic: Shopify serves stores behind its CDN with compression. Nothing to configure. Wix, Squarespace and Webflow work the same way.

Laravel

Versions Laravel 11 to 13, with Forge, Laravel Cloud or Vapor as of November 2026.

Do not compress in a PHP middleware: leave it to the web server or the CDN, which are more efficient. With Laravel Forge, the generated Nginx configuration already enables Gzip; with Laravel Cloud or Vapor, compression is handled by the platform.

Next.js

Versions Next.js 15 and 16 (next start or custom server).

next start compresses with Gzip by default. If a proxy or CDN already does it, turn it off to avoid doing the work twice:

// next.config.js
module.exports = {
  compress: false,
};

Common mistakes

  • Testing with curl -I without an Accept-Encoding header: curl announces no algorithm by default, so the server responds without compression and you wrongly conclude it is inactive.
  • Forgetting Vary: Accept-Encoding: an intermediate cache can then serve a compressed version to a client that does not understand it.
  • Compressing images and WOFF2 fonts: no gain, wasted CPU.
  • Incorrect MIME types: a JavaScript file served as text/plain or application/octet-stream escapes the rules. Check the Content-Type header of each file type.
  • Maximum compression level on the fly: Brotli 11 on every request slows the server down more than it lightens the response.
  • Believing the CDN is enough: if the origin does not compress, the origin-to-CDN leg stays slow for uncached pages.
  • Not purging: after enabling compression, caches (CDN, Varnish, caching plugin) keep serving the old uncompressed version.

Frequently asked questions

Should I enable Brotli if Cloudflare already compresses?

Yes, keep compression on the origin server even behind Cloudflare. Cloudflare compresses what it serves to visitors, but the pages it does not cache first travel from your server: compressing them at the origin speeds up that leg and reduces the bandwidth billed by your host. Just avoid adding a third layer of compression in the application.

Brotli or Gzip: which one should I choose?

Enable both. Brotli compresses text files better and every current browser supports it over HTTPS; the server sends it to browsers that announce it in the Accept-Encoding header. Gzip remains the universal fallback for other clients. On the fly, aim for a Brotli level of 4 to 6 and Gzip of 5 to 6; maximum levels are for files precompressed at build time.

Does Gzip compression improve SEO?

Not directly: HTTP compression is not a ranking factor. It reduces the size of HTML, CSS and JavaScript, which speeds up the first render and LCP, especially on mobile, and so contributes to Core Web Vitals, one signal among many others. It also lightens page downloads for Googlebot, an effect that is only noticeable on very large sites.

Should I compress images and WOFF2 fonts?

No. JPEG, PNG, WebP, AVIF, videos, archives and WOFF and WOFF2 fonts are already compressed: applying Brotli or Gzip to them uses CPU for no gain. Reserve compression for text formats, that is HTML, CSS, JavaScript, JSON, XML, SVG, RSS feeds, manifests and TTF or OTF fonts.

How do I know if my site is properly compressed?

Request a page with curl, adding the Accept-Encoding: br, gzip header, then read the response: a content-encoding: br or gzip line confirms compression. Without that header, curl announces no algorithm and the server responds uncompressed, which skews the test. Also check a CSS file and a JavaScript file, because static files are sometimes handled separately.

Resources

Updated on

Topic checklist (PDF)

And now?

In the “Performance and Core Web Vitals” topic

  1. Analyze PageSpeed Insights and Lighthouse
  2. Analyze real-user CrUX data
  3. Target LCP ≤ 2.5 s at the 75th percentile
  4. Target INP ≤ 200 ms at the 75th percentile
  5. Target CLS ≤ 0.1 at the 75th percentile
  6. Target TTFB ≤ 800 ms as a benchmark
  7. Optimize hosting and CDN
  8. Enable Brotli/Gzip
  9. Configure browser and server caching
  10. Minify CSS and JavaScript
  11. Remove unused CSS/JS
  12. Reduce render-blocking resources
  13. Defer non-essential scripts
  14. Limit third-party scripts
  15. Optimize database queries
  16. Optimize fonts (WOFF2, font-display)
  17. Preload only critical resources
  18. Optimize the LCP image without lazy loading
  19. Lazy-load offscreen content
  20. Reserve space for media and ads
  21. Reduce DOM complexity
  22. Test before and after cookie consent
  23. Test on a slow mobile connection
  24. Set a performance budget
  25. Preload likely navigations with Speculation Rules
  26. Make pages eligible for the back/forward cache (bfcache)
  27. Diagnose INP with Long Animation Frames (LoAF)