0

I have a blazor application where I added text compression, that way:

    context.Services.AddResponseCompression(o =>
    {
        o.EnableForHttps = true;
    });

    // We use Brotli by default : https://docs.microsoft.com/en-us/aspnet/core/performance/response-compression?view=aspnetcore-3.1
    //services.Configure<GzipCompressionProviderOptions>(o => o.Level = System.IO.Compression.CompressionLevel.Optimal);
    context.Services.Configure<BrotliCompressionProviderOptions>(options =>
    {
        options.Level = CompressionLevel.Fastest;
    });

and

app.UseResponseCompression();

When I check in my browser, it seems that the compression is activated:

enter image description here

Now, I test the web site speed and the first proposal is to add Text Compression. So, I do not understand why I have such a message:

enter image description here

Does someone have any idea of the problem?

ClubberLang
  • 1,053
  • 1
  • 9
  • 26

2 Answers2

1

The ASP.NET Core docs outline that using CompressionLevel.Fastest will result in the compression completing the fastest, not the webpage loading the fastest.

To get the highest level of compression you should use CompressionLevel.Optimal.

enter image description here

Matt Hensley
  • 831
  • 8
  • 18
1

I have find the issue, hope it will help anyone else. The call to UseResponseCompression must be placed BEFORE UseStaticFiles, that way it will also account for all the static (css,js) files.

// Must be before UseStaticFiles to compress static
//files and UseMvc to compress MVC responses
app.UseResponseCompression();

app.UseStaticFiles();
ClubberLang
  • 1,053
  • 1
  • 9
  • 26