Skip to content

Response Compression ​

Response compression settings for reducing HTTP response sizes using Brotli and Gzip algorithms.

Overview ​

json
json
{
  "ResponseCompression": {
    "Enabled": false,
    "EnableForHttps": false,
    "UseBrotli": true,
    "UseGzipFallback": true,
    "CompressionLevel": "Optimal",
    "IncludeMimeTypes": [
      "text/plain",
      "text/css",
      "application/javascript",
      "text/javascript",
      "text/html",
      "application/xml",
      "text/xml",
      "application/json",
      "text/json",
      "image/svg+xml",
      "font/woff",
      "font/woff2",
      "application/font-woff",
      "application/font-woff2"
    ],
    "ExcludeMimeTypes": []
  }
}

Settings Reference ​

SettingTypeDefaultDescription
EnabledboolfalseEnable response compression for HTTP responses.
EnableForHttpsboolfalseEnable response compression for HTTPS responses.
UseBrotlibooltrueUse Brotli compression algorithm when supported by client.
UseGzipFallbackbooltrueUse Gzip compression as fallback when Brotli is not supported.
CompressionLevelstring"Optimal"Compression level: Optimal, Fastest, NoCompression, SmallestSize.
IncludeMimeTypesarray(see below)MIME types to include for compression.
ExcludeMimeTypesarray[]MIME types to exclude from compression.

Compression Levels ​

LevelDescription
OptimalBalance between compression ratio and speed (default).
FastestFastest compression with lower compression ratio.
SmallestSizeBest compression ratio but slower.
NoCompressionNo compression applied.

Compression Algorithms ​

Brotli ​

Brotli provides better compression ratios than Gzip, especially for text content. When UseBrotli is true, the server will use Brotli compression if the client supports it (indicated by Accept-Encoding: br header).

Gzip Fallback ​

When UseGzipFallback is true, the server falls back to Gzip compression for clients that don't support Brotli but do support Gzip (indicated by Accept-Encoding: gzip header).

HTTPS Compression ​

Security Consideration

Enabling compression for HTTPS responses (EnableForHttps: true) may expose your application to BREACH-style attacks. Only enable if you understand the security implications and have appropriate mitigations in place.

Default MIME Types ​

The default IncludeMimeTypes covers common compressible content:

CategoryMIME Types
Texttext/plain, text/css, text/html
JavaScriptapplication/javascript
XMLapplication/xml, text/xml
JSONapplication/json, text/json
SVGimage/svg+xml
Fontsfont/woff, font/woff2, application/font-woff, application/font-woff2

Example Configuration ​

Enable compression for production:

json
json
{
  "ResponseCompression": {
    "Enabled": true,
    "EnableForHttps": true,
    "UseBrotli": true,
    "UseGzipFallback": true,
    "CompressionLevel": "Optimal"
  }
}

High-compression configuration for bandwidth-constrained environments:

json
json
{
  "ResponseCompression": {
    "Enabled": true,
    "EnableForHttps": true,
    "UseBrotli": true,
    "UseGzipFallback": true,
    "CompressionLevel": "SmallestSize"
  }
}

Next Steps ​

Comments