Hello Support Team,
We are currently using ASP.NET Zero (ASPZERO) with a backend built on ASP.NET Core 8 (.NET 8). Our system handles API endpoints that return a large amount of JSON data (e.g. scheduling events for multiple employees over long date ranges), and we are looking to optimize payload delivery by enabling GZIP and Brotli compression.
We are considering adding the following to our Startup.cs:
services.AddResponseCompression(options =>
{
options.EnableForHttps = true;
options.Providers.Add<BrotliCompressionProvider>();
options.Providers.Add<GzipCompressionProvider>();
});
services.Configure<BrotliCompressionProviderOptions>(options =>
{
options.Level = System.IO.Compression.CompressionLevel.Fastest;
});
services.Configure<GzipCompressionProviderOptions>(options =>
{
options.Level = System.IO.Compression.CompressionLevel.Fastest;
});
Our questions are:
Is this the recommended approach to enable GZIP/Brotli compression in ASP.NET Zero, or is there an ABP/Zero-specific module or wrapper we should use?
Are there any known side effects or conflicts with existing ASP.NET Zero middleware (e.g., tenant resolution, auditing, authentication)?
Is this compression middleware already enabled in the latest ASP.NET Zero templates by default?
Do you recommend any additional configuration when using application/json APIs over HTTPS?
We’d appreciate any guidance to make sure this integrates properly within the ASP.NET Zero architecture.
Thank you!
1 Answer(s)
-
0
Hi @pliaspzero
The solution you've suggested is the correct approach. However, don't forget to add the
app.UseResponseCompression();middleware in theConfiguremethod. This middleware is responsible for applying compression to the response.In terms of ASP.NET Zero or ASP.NET Boilerplate, there isn’t a special module or wrapper for GZIP, Brotli compression. Using ASP.NET Core’s built in
AddResponseCompressionmiddleware is the correct approach. Since compression happens at the response stage, it doesn't interfere with tenant resolution, auditing, or authentication.Compression middleware is not enabled by default in ASP.NET Zero templates. You will need to manually add the
AddResponseCompressionmiddleware in yourStartup.cs.Additional Configuration Accept-Encoding Header: The client must send an Accept-Encoding header to request compressed data. Modern browsers and HTTP clients send this header automatically.
Choosing a fast compression level
(CompressionLevel.Fastest)can improve performance but reduce the compression ratio. If higher compression is desired, consider usingCompressionLevel.Optimal.Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)