Content Compression - Anycast CDN [EN]

Content Compression - Anycast CDN [EN]

Introduction to Content Compression


Content compression reduces the volume of transmitted data, improving loading times and optimizing bandwidth consumption. It is particularly beneficial for CDNs. Enabled for Anycast CDN, it optimizes delivery and enhances user experience while decreasing infrastructure costs and resource load.

Content compression involves storing compressed file copies in the cache separately for various compression methods. Though compression somewhat increases the CPU load, it significantly reduces bandwidth usage.

Eligible Content


Only specific media types are eligible for compression. Supported MIME types are listed below.

Image

  • image/svg+xml

  • image/vnd.microsoft.icon

  • image/x-icon

 

Fonts

  • font/eot

  • font/opentype

  • font/otf

  • font/ttf

  • font/x-woff

 

Multipart

  • multipart/bag

  • multipart/mixed

Application

  • application/atom+xml

  • application/eot

  • application/font

  • application/font-sfnt

  • application/font-woff

  • application/geo+json

  • application/graphql+json

  • application/javascript

  • application/javascript-binast

  • application/json

  • application/ld+json

  • application/manifest+json

  • application/opentype

  • application/otf

  • application/rss+xml

  • application/truetype

  • application/ttf

  • application/vnd.api+json

  • application/vnd.ms-fontobject

  • application/wasm

  • application/x-font-opentype

  • application/x-font-truetype

  • application/x-font-ttf

  • application/x-httpd-cgi

  • application/x-javascript

  • application/x-opentype

  • application/x-otf

  • application/x-perl

  • application/x-protobuf

  • application/x-ttf

  • application/x-web-app-manifest+json

  • application/xhtml+xml

  • application/xml

Text-based

  • text/cache-manifest

  • text/css

  • text/html

  • text/javascript

  • text/js

  • text/plain

  • text/richtext

  • text/x-component

  • text/x-java-source

  • text/x-markdown

  • text/x-script

  • text/xml

Resource Compression Configuration


Custom setup

To set up resource compression for any particular resource, navigate to the Anycast CDN Resources section of the user panel.

Within the Resources List view, select the resource in question and click on the dedicated row to access the resource page, as shown below.

Resource list view

Go to the Preferences tab and scroll to the very bottom, where content compression parameters are configurable in the dedicated section.

Check the boxes to enable compression methods and uncheck to disable them. Press Save changes to confirm and save your new compression configuration.

Resource page, preferences tab

Default configuration

The default and generally recommended configuration is depicted below:

Default configuration

If you don’t configure resource compression otherwise, it would apply to your files as follows:

  • Edge compression location is not selected; therefore, content compression will occur at the origin server.

  • The zstd compression method is not selected (being still considered experimental); therefore, it will not apply.

  • Both gzip and Brotli methods are enabled, meaning both algorithms will apply. All supporting clients will receive Brotli-compressed content. CDN will serve gzip-compressed files to Brotli-unsupportive browsers, scripts, bots, or apps.

Compression Locations


By default, the edge compression is disabled.

There are two points where CDN can compress your content:

Edge

At the Edge (on CDN nodes), compression occurs before your content is cached, ensuring that each node (or shield node if Origin Shield is enabled) stores a compressed version.

If your origin handles compression load effectively, we recommend sticking to the Origin compression and leaving the Edge compression parameter unchecked.

This is best suitable if your origin server’s processing power allows for it and you want to keep CDN processing of your files to the minimum.

Origin

The origin is your server, physical or virtual, hosting your source files directory.

At the Origin compression takes place within your origin server and reduces the processing load on CDN nodes but increases bandwidth usage between the origin and CDN.

In case performance significantly varies for different resources, consider enabling Edge compression for the resources with the most voluminous files, maintaining Origin compression as a default for the majority of your resources.

This is beneficial if you need to cut bandwidth consumption between the origin and CDN nodes and if the bandwidth is a bottleneck or incurs high costs.

Edge Compression Methods


When enabled, this parameter activates content compression on CDN nodes. The origin server will not compress files in this scenario.

All modern browsers support content compression. The following compression methods are available for Edge compression:

gzip

The gzip method is a well-established Zlib-based compression algorithm, widely supported throughout various clients.

Opt for gzip for maximum compatibility, as it is the most widely supported method. While it offers lower compression ratios than Brotli, it ensures compatibility with older clients and systems.

Brotli

Brotli is a modern and effective compression method with broad client support. It provides better compression ratios than gzip while maintaining broad browser support.

Use Brotli to optimize compression efficiency for text-based content like HTML, CSS, and JavaScript.

zstd

The Zstandard algorithm, known as zstd, is a quick and efficient compression method still considered experimental (disabled by default).

Try Zstd when high-speed compression and decompression are required, especially for dynamic or frequently changing content. It offers an excellent balance between compression speed and ratio.

Fallback priority

If a requesting client (browser, script, bot, or app) does not support your preferred compression algorithm, the CDN will serve the content using an alternative supported method. The compression priority order is as follows: Brotlizstdgzip.

In case a client does not support compression in general, content will remain uncompressed and will be cached accordingly.

Caching Compressed Content Separately


Regardless of where the file compression occurs, caching must account for different compression methods. The Cache Compressed Content Separately (CCCS approach) ensures that content compressed with different methods is stored as distinct cache objects. CCCS compression algorithms mirror Edge compression methods.

  • When Edge compression is enabled, the CDN automatically aligns cache settings.

  • If Edge compression is disabled, you must manually configure cache settings to match origin-supported methods to avoid inconsistencies.

Accept-Encoding Header role


The HTTP request header is a key-value pair sent by a requesting client to the CDN node, providing additional information.

The Accept-Encoding header indicates which compression methods a particular requesting client supports. The CDN selects a method based on its priority and cache availability.

  • When Edge compression is Enabled: The CDN does not pass the Accept-Encoding header to the origin, ensuring the origin does not compress content. This reduces the origin CPU load but increases bandwidth usage.

  • When Edge Compression is Disabled: The CDN filters methods based on client support and cache settings, forwarding only the optimal method out of the supported ones to the origin. The origin compresses content accordingly, and the CDN caches it.

Please note: The Accept-Encoding header also affects the cache key, impacting cache hit rates. If the origin does not support a selected compression method, uncompressed content may be cached instead, potentially reducing cache efficiency.

Warmup Compression


CDN warm-up functionality (pre-caching your content) is available via the API. Compression settings impact this process and must be configured within the API.

Supported warmup compression methods align with both Edge compression and CCCS, and an additional Raw (uncompressed) option.

Uncompressed content warm-up is generally useless since modern browsers, apps, and web crawlers cover it on their side.

Modes

Selected methods, whether automatic or manual, ensure content is compressed and cached correctly for optimal delivery.

Automatic Mode (default)

You haven’t specified any compression methods via the API; CDN uses all enabled CCCS methods. The raw method is implemented only if no compression methods are enabled.

Manual Mode

You have selected specific compression methods to be used, CCCS and/or raw.

For more details on cache warm-up API integration, refer to the API documentation.