ASP.NET Core Interview Question #94
What is response compression middleware?
Middleware & Request Pipeline Mid-Level Intermediate
Quick Interview Answer
Response compression reduces the size of eligible HTTP responses before they are sent to clients. This can reduce bandwidth usage and improve transfer time for compressible content such as JSON, HTML, CSS, and JavaScript.
Detailed Explanation
Response compression reduces the size of eligible HTTP responses before they are sent to clients. This can reduce bandwidth usage and improve transfer time for compressible content such as JSON, HTML, CSS, and JavaScript.
The services are registered with AddResponseCompression(), and the middleware is enabled with UseResponseCompression().
Compression consumes CPU, so it should be configured appropriately. Some responses are already compressed, and sensitive scenarios may require additional consideration before compression is enabled.
Code Example
builder.Services.AddResponseCompression();
var app = builder.Build();
app.UseResponseCompression();
app.MapControllers();