Response compression is available from the Microsoft.AspNetCore.ResponseCompression package. Essentially, for browsers that support it, it can compress the response before sending it through the wire, thereby minimizing the amount of data that will be sent, at the expense of consuming some time compressing it.
If a browser supports response compression, it should send an Accept-Encoding: gzip, deflate header. Let's see how:
- We first need to register the response compression services in ConfigureServices:
services.AddResponseCompression();
- A more elaborate version allows you to specify the actual compression provider (GzipCompressionProvider is the one included) and the compressible file types:
services.AddResponseCompression(options =>
{
options.EnableForHttps = true;
options.Providers.Add<GzipCompressionProvider>();
options.MimeTypes = ResponseCompressionDefaults...