File compression

Updated at:

ESA compresses static resources to reduce transfer sizes and speed up page loading.

Introduction

ESA provides three compression methods: Gzip, Brotli, and Zstd. Each method offers different trade-offs in compression efficiency, decompression speed, and compatibility.

Compression type

Compression efficiency

Compatibility

Use case

Gzip

Fast compression, medium decompression speed

High

General web services

Brotli

Slow compression, high decompression speed

Medium

Static resource optimization

Zstd

Very fast compression, very fast decompression

Low

Real-time stream data processing

Note

The Entrance plan only supports Zstd compression.

Notes

  • If you enable Gzip, Brotli, and Zstd at the same time, they are applied in the following order: Zstd > Brotli > Gzip.

  • ESA supports compression for the following file types: text/xml, text/plain, text/css, application/javascript, application/x-javascript, application/rss+xml, text/javascript, image/tiff, image/svg+xml, application/json, and application/xml.

Cases where compression rules do not take effect

Compression rules may not take effect in certain cases due to conflicting settings on the origin server or client.

For origin server

  • Gzip or Brotli compression applies only to origin server files between 1 KB and 10 MB. Files outside this range are not compressed.

  • If the origin server response includes the Content-Encoding header, ESA does not apply compression.

  • If the origin server response contains the cache-control: no-transform HTTP header, ESA does not apply compression.

For client

If a client does not support the configured compression algorithm, the response is returned uncompressed. Client support is indicated by the Accept-Encoding request header.

Note

File compression rules apply only to requests that match the specified rule conditions. For more information about how to configure site-level compression rules, see Gzip, Brotli, and Zstd.

Add a file compression rule

  1. In the ESA console, select Websites. In the Website column, click the target site.

  2. In the navigation pane on the left, select Rules > Content Optimization.

  3. Click Create Rule and enter a Rule Name.

  4. In the If requests match... section, set the conditions that the request must match. For more information about how to configure rules, see Components of a rule expression.

  5. In the Then execute... section, enable the required compression method.

    Rule item

    Description

    Rule Name

    A custom rule name. It can contain Chinese characters, letters (case-sensitive), digits (0-9), and underscores (_). The name can be up to 64 characters long.

    Matching conditions

    Specify the conditions that requests must match.

    Click the logical operator And or Or to add a condition. You can add up to five conditions to a rule.

    Each condition consists of a Matching field, a Logical operator, and a Matching content.

    Compression method

    Enable Gzip, Brotli, or Zstd. When all three are enabled, Zstd has the highest priority, followed by Brotli.

Related documentation

Rule-related features vary in effective priority, reentrancy, and effective granularity. For details, see Characteristics of rule-based features.