loading...

How to add gzip compression to ASP.NET Core API responses

canro91 profile image Cesar Aguirre Originally published at canro91.github.io ・1 min read

If you're using ASP.NET Core 2.x, you need to install the NuGet Microsoft.AspNetCore.ResponseCompression

public void ConfigureServices(IServiceCollection services)
{
    services.Configure<GzipCompressionProviderOptions>(options => 
    {
        options.Level = CompressionLevel.Fastest;
    });
    services.AddResponseCompression(options =>
    {
        options.Providers.Add<GzipCompressionProvider>();
    });
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseResponseCompression();
}

Source: Response compression in ASP.NET Core

Discussion

pic
Editor guide