There is a surprisingly common form of storage duplication in static website deployments: every generated HTML page is stored in its original form, even though the web server usually delivers a compressed representation to the browser. When a website contains a large number of generated pages, those unnecessary originals can occupy substantial disk space.
The important distinction is that a browser needs the correct HTML document, not necessarily an uncompressed HTML file sitting on the production filesystem. HTTP supports content encoding, allowing the server to deliver the same document using Brotli or Gzip. The browser transparently decompresses the response before processing it.
This raises a practical architectural question: why keep three copies of every generated page when production can serve precompressed files and reconstruct an uncompressed response only when necessary?
The original HTML is not necessarily a production requirement
Consider a typical static export. A generated page might exist in three forms:
index.html
index.html.br
index.html.gz
All three files represent the same HTML document. The first is the original output, the second is Brotli-compressed, and the third is Gzip-compressed.
Keeping the original during the build is useful. It provides a canonical source for generating compressed representations and verifying their integrity. Keeping it permanently in every production release, however, is a separate decision.
If the deployment process already produces valid Brotli and Gzip files, the uncompressed production copy may be redundant. The server can select a compressed representation according to the client's capabilities. The public page URL does not need to change, and the browser does not need to know which physical file the server used.
This is especially relevant to large static exports. The more generated pages a site contains, the more unnecessary duplication can accumulate when every original HTML file is deployed alongside its compressed copies.
What browsers actually request
Browsers and HTTP clients advertise supported content codings through the Accept-Encoding request header. A typical request might contain:
Accept-Encoding: gzip, deflate, br
This means the client can accept the listed encodings. It does not request a particular filename or extension. The server is responsible for selecting an acceptable representation.
When returning Brotli-compressed HTML, the server normally sends headers similar to:
Content-Type: text/html; charset=utf-8
Content-Encoding: br
Vary: Accept-Encoding
For Gzip, the content encoding is gzip. The browser automatically decompresses the response. The document remains HTML from the application's perspective.
Consequently, saying that users do not request HTML is technically inaccurate. They request HTML pages constantly. The important observation is that many clients receive those pages in compressed form. The question is whether the production server needs to store an additional uncompressed copy merely to satisfy those requests.
Measure actual responses instead of guessing
Browser compatibility statistics are useful, but they cannot tell you what your own server is delivering. A website might support Brotli while still returning Gzip because of an incomplete configuration, a proxy, a cache, or an application response.
The most useful measurement compares two values:
Accept-Encoding: the encodings advertised by the client.Content-Encoding: the encoding actually used in the response.
For example, Nginx can temporarily record both:
log_format compression
'$time_iso8601 '
'status=$status '
'accept="$http_accept_encoding" '
'sent="$sent_http_content_encoding" '
'type="$sent_http_content_type"';
access_log /var/log/nginx/compression.log compression;
This makes it possible to distinguish clients that advertise Brotli support from responses that actually use Brotli. It also reveals Gzip and identity responses.
In a real production measurement across multiple static sites, approximately 78% of observed HTML responses used Brotli, approximately 22% used Gzip, and only a very small fraction were uncompressed. This was a limited observation of actual requests, not a universal statistic or a measurement of unique visitors. Nevertheless, it demonstrated that keeping an uncompressed copy for every response was difficult to justify.
There is an important distinction between requests and people. Access logs count HTTP requests, not unique users. A single browser can make many requests, and automated clients can contribute substantially to the total. User-Agent strings are useful diagnostic clues, but they do not reliably establish whether a request came from a person, a search engine, or another automated system.
Generate compressed representations locally
A clean architecture moves compression work into the build pipeline.
The original HTML is generated on the development machine or build environment. The pipeline then creates both compressed representations:
page.html
├── page.html.br
└── page.html.gz
Before deployment, both compressed files should be decompressed and compared with the original source.
decompress(page.html.br) == page.html
decompress(page.html.gz) == page.html
The comparison should be byte-for-byte. Merely checking that the output looks like valid HTML is insufficient. Differences in whitespace, metadata, canonical links, structured data, or other markup can introduce subtle inconsistencies.
The deployment package can then contain:
- The precompressed Brotli HTML files.
- The precompressed Gzip HTML files.
- All other required application assets.
The generated uncompressed HTML does not need to be transferred into the active production release.
This does not mean deleting the original from the build pipeline. It remains the canonical source used to generate and validate both compressed representations. The optimization concerns production storage, not the reproducibility of the build.
Serve Brotli and Gzip directly
Precompression avoids repeatedly compressing identical static documents during production requests. Instead of spending CPU time generating a compressed response, the web server reads the appropriate file and sends it directly.
With Nginx, the relevant capabilities are commonly provided by three modules:
ngx_brotlistatic support for precompressed Brotli files.ngx_http_gzip_static_modulefor precompressed Gzip files.ngx_http_gunzip_modulefor decompressing Gzip responses when a client cannot accept Gzip.
The intended behavior is straightforward:
| Client capability | Server behavior |
|---|---|
| Accepts Brotli | Serve the prebuilt Brotli file. |
| Accepts Gzip but not Brotli | Serve the prebuilt Gzip file. |
| Accepts neither coding | Decompress the Gzip file and return identity-encoded HTML. |
The public URL remains unchanged. A request for /articles/example/ should continue to work even if the production directory contains only compressed representations of the generated HTML.
Nginx configurations may use directives such as brotli_static, gzip_static, and gunzip. One possible design uses gzip_static always together with gunzip on, allowing the Gzip sidecar to provide the source for an identity response. The Brotli module can serve Brotli directly when appropriate.
These directives must be tested together against the actual installed Nginx build. Module availability, filter ordering, location inheritance, content negotiation, and proxy behavior matter. A configuration that works in an isolated example is not automatically correct for every production routing setup.
Why Gzip still matters
Brotli is an excellent choice for modern browsers, but it should not be treated as the only encoding worth supporting. Gzip remains an important compatibility option for older clients, HTTP libraries, command-line tools, automated systems, and other software that does not advertise Brotli support.
Removing Gzip simply because most modern browsers support Brotli can create unnecessary compatibility problems. The production measurement described earlier showed a meaningful share of Gzip responses, so preserving that path was the safer decision.
There is another practical reason to keep Gzip: Nginx has native support for decompressing Gzip responses. This makes it possible to serve an uncompressed HTML response without permanently storing the original file.
In other words, Gzip is not merely a fallback for older clients. It can also serve as the intermediate representation used to reconstruct identity-encoded HTML.
What about storing only Brotli?
If disk space is extremely constrained, storing only Brotli may appear even more attractive. It removes the need to keep a second compressed representation. However, it changes the decompression requirements.
Nginx's native gunzip module decompresses Gzip. It does not decompress Brotli. Enabling gunzip cannot turn a Brotli-only deployment into a system that serves uncompressed HTML.
A Brotli-only architecture therefore needs a separate decompression capability, such as a suitable Nginx module or a carefully designed local handler. That component must correctly handle response headers, streaming, errors, caching, and concurrent requests. It also becomes another part of the production system that needs maintenance and testing.
There is nothing inherently wrong with this design when disk pressure justifies the additional complexity. But it is not equivalent to keeping both compressed formats and using Nginx's native Gzip decompression.
For a conventional Nginx deployment, prebuilt Brotli plus prebuilt Gzip is usually the more practical balance. It keeps both common compressed response paths efficient and provides a native route to identity responses.
Content negotiation and caching need careful testing
Compression is not only a matter of selecting a file extension. The server must respect the client's actual encoding preferences, including quality values and explicit rejection.
For example:
Accept-Encoding: br;q=0, gzip;q=1
This explicitly rejects Brotli while accepting Gzip. A server must not return Brotli merely because the browser generally supports it.
Similarly, a request with no Accept-Encoding header must not be treated as proof that the client accepts every compression format. The server should follow HTTP content-negotiation rules and return an acceptable representation.
Responses that vary according to Accept-Encoding should carry the appropriate Vary: Accept-Encoding header. Otherwise, an intermediary cache may reuse a Brotli response for a client that cannot decode it, or reuse another representation incorrectly.
Test the complete request path, including any reverse proxy or CDN. Correct behavior at the origin does not guarantee that every intermediary preserves the same negotiation semantics.
Do not overlook routing, ranges, and SEO
A compressed-only migration can fail even when the compression modules work correctly. Static routing often assumes that an uncompressed .html file exists. Direct file lookups, try_files rules, directory indexes, internal redirects, and error-page handling may all depend on the previous layout.
Before removing originals, verify that the same public URLs still resolve to the correct pages. Preserve canonical URLs, localized routes, redirects, status codes, metadata, structured data, and sitemap behavior. The compressed sidecar extensions should remain internal storage details rather than becoming new indexable URLs.
Also test HEAD requests, conditional requests, cache validators, and byte-range behavior. A decompression filter can affect range handling. For example, Nginx may ignore a Range request for an identity response produced by decompression and return the complete document with 200 OK instead of 206 Partial Content. A server is allowed to ignore a Range request, but the behavior should be understood and tested against the application's requirements.
For ordinary HTML navigation, a complete response is generally sufficient. However, do not assume that every response path is equivalent simply because the homepage loads successfully.
A safe migration sequence
The safest approach is to make the migration additive before making it destructive.
- Inventory the deployment. Identify generated HTML, existing compressed sidecars, routing rules, and the Nginx modules available in production.
- Measure actual responses. Record the client's advertised encodings and the content encoding actually sent.
- Update the local build. Generate Brotli and Gzip representations from the original HTML.
- Validate every page. Decompress both outputs and compare them byte-for-byte with the source.
- Update packaging. Include both compressed representations and exclude generated uncompressed HTML from the production package.
- Test the Nginx layout. Verify Brotli, Gzip, and identity responses using real HTTP requests.
- Check all routes. Include nested pages, directory indexes, redirects, localized URLs, and error pages.
- Deploy incrementally. Start with a low-risk release and retain a reliable rollback path.
- Remove redundant originals. Do this only after the compressed representations and production behavior have been verified.
Automate these checks in the release pipeline. A deployment should not switch traffic to a new release if a compressed file is missing, stale, corrupt, or produces content different from the expected source. If verification fails, the previous working release should remain available.
Keep recoverable build artifacts outside the active production directory. The goal is to eliminate redundant production copies, not to make future rebuilds or rollbacks impossible.
The practical rule: store what production needs to serve
For a large static website, storing every original HTML file alongside Brotli and Gzip copies is often unnecessary. Generate the canonical HTML during the build, create and verify both compressed representations, and deploy those representations instead of the uncompressed originals.
Serve Brotli to clients that accept it. Serve Gzip to clients that need it. When a client requires identity-encoded HTML, use Nginx's Gzip decompression capability rather than keeping a permanent uncompressed copy on disk.
If storage constraints are severe enough to justify Brotli-only storage, account for the fact that native Nginx gunzip does not decompress Brotli. Provide and test a real Brotli decompression path before removing Gzip.
The broader engineering principle is simple: the build needs the original source; production needs the representations it actually serves. Keeping an uncompressed duplicate on the production filesystem should be a deliberate requirement, not an automatic consequence of how a static site was generated.