1

I just did a Google PageSpeed Insights test on a website that is hosted on an Azure Service Linux using a Docker Container.

The result was not good, the primary thing it complained about is that none of the requests are gzipped.

I searched a bit and found no details on how to enable this for a container service. Answers such as this one only pertain to a regular website with a web.config, which I dont have. Enabling gzip compression on Azure App Service

I found that I can enable this in asp net core (what I'm hosting in my container) using this. But I would prefer if the hosting server did it as I'm sure that would be more performant. Which is also what the documentation says on that page.

Use server-based response compression technologies in IIS, Apache, or Nginx. The performance of the middleware probably won't match that of the server modules.

So, how do I enable Gzip compression in an App Service using Containers running on Linux?

JensB
  • 6,663
  • 2
  • 55
  • 94

2 Answers2

2

I ended up doing this. I don't think there is a way to enable compression in App services using containers.

This is a lot better than nothing.

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddResponseCompression();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseResponseCompression();
    }
}
JensB
  • 6,663
  • 2
  • 55
  • 94
  • You need to enable https compression but make sure you use anti forgery token to prevent CRIME attacks. More info: https://learn.microsoft.com/en-us/aspnet/core/performance/response-compression?view=aspnetcore-6.0 – Orestis P. Oct 05 '22 at 14:24
-1

Are you using any webserver to serve the requests (e.g. IISC, apache etc)? If so, better approach would be to enable gzip compression in the webserver than to enable compression in app server. The warning is also suggesting that only.

Atul
  • 1,116
  • 1
  • 10
  • 20
  • 2
    "Azure App Service for Containers" I don't have any control of any IIS or Apache server. – JensB May 12 '20 at 11:43
  • Can you check answer to question - https://learn.microsoft.com/en-us/azure/app-service/faq-availability-performance-application-issues#how-do-i-turn-on-failed-request-tracing ? Please ignore the question but see how the web.config setting is exposed from azure portal. If you are able to see it, this could be the way the settings are exposed (for webserver). – Atul May 13 '20 at 03:39