Loading...

CDN.com.tr Help

Brotli and gzip compression

The edge compresses text responses automatically: Brotli for browsers that support it, gzip for the others. See which method each domain uses on the Compression card and confirm it with curl.

Brotli and gzip compression

The edge compresses text responses automatically: Brotli for browsers that support it, gzip for the others. See which method each domain uses on the Compression card and confirm it with curl.

Related guides

The other response header to read while you test, what happens to images, and the rules the card refers to.

While testing

Read cache status: HIT, MISS, BYPASS, EXPIRED

The X-Proxy-Cache-MT header shows whether the answer came from the cache.

Open the topic
Delivery rules

Write cache behavior with Add Rule

The rules listed on the same page; the note under each compression value names one of them.

Open the topic

Panel path

  1. Management Panel
  2. Delivery Rules
  3. Optimization
  4. Compression

Prerequisites

  • A domain served by a delivery rule: the Compression card lists the domains the account's rules serve.
  • curl, or your browser's developer tools, for the check.

Step-by-step guide

1

Read the Compression card

The card shows each domain's compression over HTTP and HTTPS.

  • Open Delivery Rules and go to the Optimization tab.
  • In the Compression card, find your domain under Domain.
  • Read the values under HTTP and HTTPS, and the note under each.

Expected result: A domain served with the default settings shows Brotli + gzip, with a note such as from rule #… or from the certificate-check rule.

2

Check Brotli and gzip with curl

Request a text file of at least 256 bytes, such as a CSS or JavaScript file, once asking for Brotli and once for gzip.

  • Send a GET request with Accept-Encoding: br and read the response headers.
  • Repeat it with Accept-Encoding: gzip.

Expected result: content-encoding: br on the first answer and content-encoding: gzip on the second, each with vary: Accept-Encoding.

cdnctl equivalent
curl -s -o /dev/null -D - -H 'Accept-Encoding: br' https://www.example.com/assets/app.css | grep -iE '^(content-encoding|vary):'
curl -s -o /dev/null -D - -H 'Accept-Encoding: gzip' https://www.example.com/assets/app.css | grep -iE '^(content-encoding|vary):'
3

Compare the sizes

The download size shows what compression saves on your own files.

  • Download the file once with Accept-Encoding: br and once without an Accept-Encoding header.
  • Compare the two byte counts.

Expected result: Two byte counts: the compressed size first, then the uncompressed size.

cdnctl equivalent
curl -s -o /dev/null -w '%{size_download}\n' -H 'Accept-Encoding: br' https://www.example.com/assets/app.css
curl -s -o /dev/null -w '%{size_download}\n' https://www.example.com/assets/app.css

Verification

  • curl -s -o /dev/null -D - -H 'Accept-Encoding: br' https://www.example.com/assets/app.css | grep -iE '^(content-encoding|vary):' → content-encoding: br, vary: Accept-Encoding
  • curl -s -o /dev/null -D - -H 'Accept-Encoding: gzip' https://www.example.com/assets/app.css | grep -iE '^(content-encoding|vary):' → content-encoding: gzip, vary: Accept-Encoding
  • curl -s -o /dev/null -w '%{size_download}\n' -H 'Accept-Encoding: br' https://www.example.com/assets/app.css → the compressed size; the same command without the Accept-Encoding header → the uncompressed size

Use cases

You moved a site behind the CDN and want to confirm that its HTML, CSS, JavaScript and JSON reach visitors compressed, without setting up compression on your origin.

Quick workflow

  1. Open Delivery Rules for the account and go to the Optimization tab.
  2. In the Compression card, marked Automatic, find your domain's row.
  3. Read the HTTP and HTTPS columns: Brotli + gzip means both methods are on for that protocol, and the note under the value names the rule it comes from. gzip only, Brotli only or Off means the domain's oldest rule was saved with that setting; the note names that rule.
  4. Request a CSS or JavaScript file with curl and read the content-encoding header.

Checks

  • The edge compresses by the response's Content-Type: HTML, CSS, JavaScript, JSON (application/json, application/ld+json, application/manifest+json), XML (RSS and Atom feeds included), plain text, SVG, ICO icons, WebAssembly, and TTF, OTF and EOT fonts. Other content types go out as they are.
  • JPEG, PNG, WebP and other image formats except SVG and ICO, WOFF and WOFF2 fonts, video and zip archives are already compressed formats and go out as they are.
  • Responses of a known size under 256 bytes go out uncompressed.
  • Compression applies to 200, 403 and 404 responses.
  • Compressed responses carry Vary: Accept-Encoding, so caches in between keep the compressed and uncompressed versions apart.
  • Browsers ask for Brotli only over HTTPS; over plain HTTP the same browser gets gzip.
  • The edge does the compression, so your origin does not need to. A response that arrives already compressed (it has a Content-Encoding header) is not compressed again.
  • When you edit a rule, a Per domain note appears for each of its domains whose compression comes from an older rule, and names that rule.
  • Compression is set per domain by its oldest rule, not per rule: the value on the card, including gzip only, Brotli only or Off, applies to every rule of the domain over that protocol, and it can't be changed on the card.

Frequently asked questions

Do I need to turn compression on?

No. Compression is automatic: delivery rules are created with Brotli and gzip, and the Compression card is marked Automatic.

Why does my check show no content-encoding header?

Check five things: the Compression card shows Brotli + gzip for that domain and protocol, the request asks for compression (curl sends no Accept-Encoding header unless you add one), the file is one of the compressed types, it is at least 256 bytes, and the status is 200, 403 or 404. Run the verification commands below as written.

Brotli or gzip: which one does a visitor get?

Brotli for browsers that support it, gzip for the others. The edge reads the Accept-Encoding header the browser sends, and browsers ask for Brotli only over HTTPS.

What does “Not served” mean on the card?

No delivery rule serves that domain over that protocol yet. Once a rule serves the domain over HTTP or HTTPS, the card shows its compression there.