Your product images may get most of the attention, but every storefront also loads HTML, CSS, JavaScript, and other text-based files. If those files are larger than they need to be, shoppers may spend longer waiting for your pages to become usable—especially on mobile connections.
Brotli compression can reduce the amount of text-based data transferred to a visitor’s browser. To enable it, you need control over the server or CDN that delivers your storefront assets, then you need to confirm that eligible responses actually use it. Here’s how to make that change safely and verify the result.
What Brotli compression does for an ecommerce storefront
Brotli is a compression format supported by modern browsers. When a browser requests a file, it can indicate that it accepts Brotli. If your server or CDN is configured to use it, the response may include a compressed version of the file and a Content-Encoding: br header. The browser decompresses it automatically.
Brotli is useful for text-based resources such as product-page HTML, stylesheets, JavaScript, JSON, and SVG files. It generally does not help with formats that are already compressed, such as JPEG, PNG, WebP, AVIF, and most video files.
Compression reduces transfer size; it does not fix every performance problem. A large JavaScript bundle still needs to be downloaded, parsed, and run. Treat Brotli as one part of storefront performance work, alongside image optimization, sensible caching, and limiting unnecessary scripts.
Find out who controls your storefront asset delivery
Before changing a setting, identify where your storefront files are served. The answer determines whether you can enable Brotli yourself.
- Hosted ecommerce platform: Your platform may manage compression and CDN delivery for you. You might not have access to web-server settings, so test first and consult its current documentation before trying to change anything.
- Self-hosted store: If you manage Nginx or Apache, you may be able to configure Brotli at the web-server level.
- CDN in front of your store: Your CDN may compress eligible responses even if your origin server does not. Check which layer serves the public URL shoppers use.
- Third-party apps and scripts: Files loaded from another company’s domain are controlled by that provider. Your compression settings generally will not change those responses.
Make a short list of representative URLs before you begin: a product page, a CSS file, a JavaScript file, and—if your store serves one—an SVG asset. Use the actual public asset URLs, which may have a different hostname from your storefront.
How to enable Brotli compression
Option 1: Turn it on at your CDN
If your CDN offers a Brotli or compression setting, this is often the simplest place to start. Find the setting in your CDN’s performance or optimization controls, enable it, and allow time for the configuration to take effect. Setting names and eligibility rules vary by provider, so use its current documentation rather than assuming every response will be compressed.
Check whether the CDN requires a particular minimum file size, compresses only certain content types, or changes its behavior when the origin already sends a compressed response. Most importantly, verify the public CDN URL, not just the origin server: that is the response your shoppers receive.
Option 2: Configure Brotli on Nginx
Nginx needs a Brotli module available in your installation; do not assume it is included. Confirm that your hosting environment supports the module before adding Brotli directives. Then configure compression for appropriate text-based responses. A typical setup uses the following directives in an applicable Nginx configuration context:
- brotli on; enables Brotli compression.
- brotli_comp_level 5; sets a moderate compression level to start with.
- brotli_types text/plain text/css application/javascript application/json image/svg+xml; identifies additional eligible content types. The Nginx Brotli module handles text/html separately.
Your site may serve JavaScript, fonts, or other resources under different MIME types, so review the response headers for your real assets rather than copying a type list blindly. Keep gzip available as a fallback for clients that do not accept Brotli. Before applying a change, validate the Nginx configuration with nginx -t, then reload the service using the method appropriate for your hosting setup.
Option 3: Configure Brotli on Apache
For Apache, first confirm that mod_brotli is available and enabled. In the appropriate server or virtual-host configuration, AddOutputFilterByType BROTLI_COMPRESS text/html text/plain text/css application/javascript application/json image/svg+xml is one way to apply Brotli to eligible types.
The exact configuration depends on your Apache version, hosting permissions, and existing filters. If your provider manages Apache for you, ask whether Brotli is already active before changing configuration. Validate your configuration and test the storefront after deployment.
What if your platform does not expose a Brotli setting?
Do not install a plugin or add a second CDN solely because you cannot find a compression switch. First, inspect the response your platform already delivers. A hosted platform may handle compression automatically, and adding another layer can complicate caching or troubleshooting without improving the result.
How to verify Brotli is working
A checked setting is not proof that shoppers receive compressed files. Test the response headers for your live storefront and for individual assets.
- Open your storefront in a browser. In its developer tools, open the Network panel and reload the page.
- Select an eligible request. Start with the HTML document, then inspect a CSS or JavaScript file. If assets load from a separate CDN hostname, check those requests individually.
- Inspect the response headers. Look for Content-Encoding: br. That indicates the selected response was delivered with Brotli compression.
- Compare transferred and resource sizes. Browser developer tools may show a smaller transferred size than the resource size. This is useful supporting evidence, though caching and tool display conventions can affect the numbers.
- Repeat on key URLs. Test at least one product page and the main asset types your theme uses. One compressed homepage response does not prove every storefront file is compressed.
You can also request an asset from a command line. For example, run curl -sS -D – -o /dev/null -H ‘Accept-Encoding: br’ https://your-actual-asset-url, replacing the example address with a real URL from your store. Check the returned headers for Content-Encoding: br and a successful response status. Some servers treat HEAD requests differently from GET requests, which is why this example performs a GET while discarding the response body.
For a comparison, request the same URL with Accept-Encoding: gzip and inspect its response. Where a cache serves different versions based on compression support, Vary: Accept-Encoding is an important header to check as part of your CDN and origin configuration.
If the response does not say “Content-Encoding: br”
A missing Brotli header does not always mean something is broken. Work through these checks before changing more settings:
- Confirm the request advertises Brotli support. Without Accept-Encoding: br, the server has no reason to choose Brotli.
- Check the file type and size. Already-compressed images are poor test cases, and some services skip very small files.
- Inspect the final response, not just a redirect. Follow the request to the asset or page that actually returns content.
- Check the serving hostname. Your product page, theme assets, and third-party scripts may come from different systems.
- Review CDN caching. An older cached response may need to expire or be refreshed before you see a configuration change.
- Confirm the server module and configuration are active. A valid-looking Nginx or Apache directive will not help if the required module is missing or the configuration is not applied to that site.
After enabling Brotli, browse your store as a customer would. Check a product page, search or collection page, cart, and checkout where you have permission to test it. Compression should be invisible to shoppers; broken styling or scripts call for an immediate rollback and investigation.
Make the performance work count
Brotli is a worthwhile check because it can reduce the transfer size of the text files your storefront already sends. The practical sequence is simple: identify who serves each asset, enable compression where you have control, and verify Content-Encoding: br on live, eligible responses.
Once that is confirmed, look at what your store sends in the first place. Review heavy theme scripts, unused app assets, image sizes, and caching behavior. A smaller transfer helps, but removing an unnecessary request can be even more valuable. Start by testing one product page and its CSS and JavaScript files today; you will have a clear baseline for your next storefront improvement.
Veelgestelde vragen
Is Brotli better than gzip for every storefront file?
No. Brotli is particularly useful for text-based content, but the result depends on the file and server configuration. Keep gzip as a fallback for clients that do not support Brotli, and do not expect meaningful savings from already-compressed images or video.
Do I need to enable Brotli separately for my CDN and origin server?
Not necessarily. What matters to shoppers is the response from the public URL. Your CDN may handle compression itself, pass through a compressed origin response, or apply rules based on its configuration. Test the final response and consult your provider’s documentation before configuring both layers.
Will Brotli automatically improve my Core Web Vitals?
No improvement is guaranteed. Smaller text transfers may help loading under some conditions, but Core Web Vitals also depend on factors such as server response time, rendering, JavaScript execution, images, and layout stability. Measure your pages before and after the change.
Why does my HTML use Brotli while an image does not?
That is usually expected. HTML is text and often compresses well. Common storefront image formats are already compressed, so applying Brotli to them generally offers little benefit.