Guig
Guig

Reputation: 10387

Is it possible to set Brotli compression level dynamically based on the request headers in Nginx?

I'm using Brotli for response compression, and doing this in Nginx using nginx-brotli module.

I would like to set the value for brotli_comp_level dynamically based on the request headers, so that clients on slow networks could request higher compression. How can I achieve this?

I tried to no avail:

http {
  ...

  brotli on;
  brotli_comp_level 6;
  brotli_types *;

  if ($http_x_brotli_high_quality) {
    brotli_comp_level 11;
  }
}

Upvotes: 0

Views: 408

Answers (1)

Danila Vershinin
Danila Vershinin

Reputation: 9875

It is not possible with the stock/packaged Brotli module from NGINX Plus.

You can, however, custom compile (not recommended for production) with the following pull request integrated.

Or, if the budget allows, use the nginx-module-brotli module package from NGINX Extras, which has the aforementioned pull request integrated into the packages. This option requires a CentOS/RHEL machine and maintaining a paid subscription with GetPageSpeed.

Upvotes: 1

Related Questions