DEV Community 👩‍💻👨‍💻

Cesar Aguirre
Cesar Aguirre

Posted on • Originally published at canro91.github.io

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

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();
}
Enter fullscreen mode Exit fullscreen mode

Source: Response compression in ASP.NET Core

Top comments (0)

Join us at DEV
Yes, this is technically an “ad”, but really we just want to ask if you want to join DEV. We have 900k+ developers reading, posting, and enjoying community, and would love to have you.   Create an account and continue your coding journey.