Ali Jebali
Ali Jebali

Reputation: 134

ASP.Net Core Force to Use Brotli

It doesn't matter what I do in AddResponseCompression(), Web Service always Compress with Gzip. I want to Use brotli. I've tested :

builder.Services.AddResponseCompression();

///////////

builder.Services.AddResponseCompression(options =>
{
    options.Providers.Add<BrotliCompressionProvider>();
});

///////////

builder.Services.AddResponseCompression(options =>
{
    options.MimeTypes = new[] {
        "text/html",
        "text/css",
        ..
        .
    };
    options.Providers.Add<BrotliCompressionProvider>();
});

///////////

builder.Services.AddResponseCompression(options =>
{
    options.Providers.Add<BrotliCompressionProvider>();
    options.Providers.Add<GzipCompressionProvider>();
});

As you can see in the image below, always Gzip. But I found that the html page it self get br Content-Encoding.

enter image description here

It is worth mentioning that both static and dynamic content compression is enabled in IIS and all mime types are selected.

UPDATE: It suddenly Fixed! WOW. but how? nothing has changed. exactly NOTHING!

I tested again on another project. AddResponseCompression() then UseResponseCompression() after UseStaticFiles() and again the same happened. Gzip on all!

maybe I should submit an issue for Dotnet?

Upvotes: 0

Views: 489

Answers (1)

samwu
samwu

Reputation: 5185

You can set the compression method in applicationHost.config like this:

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
  <scheme name="br" dll="%ProgramFiles%\IIS\IIS Compression\iisbrotli.dll" />
</httpCompression>

More information you can refer to this link:

Higher Compression Ratio with Brotli compression.

Brotli IIS Compression Scheme Plugin.

Upvotes: 0

Related Questions