ASP.NET Core Interview Question #187

What is response compression?

Performance, Caching & HTTP Senior Advanced

Quick Interview Answer

Response compression reduces the number of bytes sent over the network for compressible responses such as HTML, JSON, CSS, and JavaScript. Smaller payloads can improve transfer time and reduce bandwidth consumption.

Detailed Explanation

Response compression reduces the number of bytes sent over the network for compressible responses such as HTML, JSON, CSS, and JavaScript. Smaller payloads can improve transfer time and reduce bandwidth consumption.

ASP.NET Core provides response compression middleware and supports compression providers such as Brotli and Gzip. Compression costs CPU, and already-compressed content such as many image formats gains little from being compressed again.

Code Example

builder.Services.AddResponseCompression();

var app = builder.Build();
app.UseResponseCompression();

app.MapControllers();