Brotli Response Compression with Automatic Gzip Fallback
This plugin adds Brotli ("br") HTTP response compression to nopCommerce, with a gzip fallback for clients that do not accept Brotli, so text responses transfer in a smaller form without theme or template changes. It also turns on compression for HTTPS responses and lets a merchant trade CPU cost against output size.
What It Does
- Brotli compression — applies Brotli ("br") encoding to eligible HTTP responses through the ASP.NET Core response compression middleware
- Gzip fallback — serves gzip-compressed responses to clients that do not accept Brotli
- HTTPS compression enabled — turns on compression for HTTPS responses, which nopCommerce core leaves off by default
- Compression mode choice — "Faster response" (Brotli quality 1, gzip Fastest) or "Smaller size" (Brotli quality 5, gzip Optimal)
- Live mode switching — a changed compression mode takes effect immediately, without an application restart
- Core setting toggle — reads and writes nopCommerce's own CommonSettings.UseResponseCompression flag from the plugin page
- Brotli priority ordering — the Brotli provider is registered ahead of gzip so it is chosen when a client accepts both equally
- Efficient buffering — writes are buffered in 64 KB chunks before encoding, avoiding the output-size penalty of compressing very small chunks at low quality
- Debug logging — a showDebugInfo toggle writes diagnostics to a log file, with Clear Log and Download Log actions in admin
- No third-party library — compression runs on the .NET runtime's own built-in Brotli encoder (System.IO.Compression.BrotliEncoder)
- Pooled buffers — encoding buffers are rented from ArrayPool<byte>.Shared to cut memory allocations under load
- Gzip provider replacement — replaces ASP.NET Core's own GzipCompressionProvider so the gzip level follows the same compression-mode setting
- Broad runtime compatibility — encodes with BrotliEncoder(quality, window) directly, since BrotliStream only accepts an explicit quality starting in .NET 9
How It Works
- Install the plugin, which registers the Brotli and gzip compression providers and enables compression for HTTPS.
- In admin, turn on Use Response Compression and pick the "Faster response" or "Smaller size" mode.
- Each eligible HTTP response is compressed with Brotli, or gzip when the client does not accept Brotli.
- A changed compression mode applies immediately; toggling Use Response Compression restarts the application domain.
Specs & Requirements
- nopCommerce — 5.00, 4.90, 4.80, 4.70, 4.60, 4.50, 4.40, 4.30, 4.20, 4.10
- Plugin type — Misc plugin that registers response-compression providers into the ASP.NET Core request pipeline