Summary
- Compression reduces ~70% of file size of text-based objects (HTML, CSS, JS, etc), resulting in faster loading and reduced CDN costs
- Brotli compression yields ~20% better results than Gzip, but not all CDNs support it
- All modern browsers support Brotli and Gzip compression and will automatically request it
- Some CDNs can compress content on the fly on their edge servers, others can only serve compressed if the origin sent compressed to CDN
Introduction to Compression
When a client/browser sends a request to the CDN, it tells the server what types of compressed content it supports by way of the Accept-Encoding
request header. The server will take this into account and send back compressed content if possible. Compression is great for performance and costs: less bytes over the wire results in better load times and less CDN costs. On average, compression reduces file size by 70% and can be as high as 90%.
Most clients (browsers, apps) can handle Gzip compressed content and Gzip is by far the most common compression algorithm used today. Brotli compression yields even better results than Gzip. Google's Ilya Grigorik published an excellent (technical) article on the Web Fundamentals site: Text compression with GZIP. You can easily find out if your site assets are being compressed with this HTTP Compression Test tool.
Brotli
Brotli is an open-source
compression algorithm created by Google in 2015.
They first used it in WOFF2 web fonts.
Brotli does a 10% to 30% better job at reducing file size than Gzip.
The larger the file, the better Brotli performs.
It's a misconception that Brotli compression is (much) slower than Gzip, but this is not true: Yes, Brotli can compress faster than gzip
All major browsers support Brotli.
Browsers that support Brotli will include br
in the Accept-Encoding
request header.
Brotli availability is restricted to HTTPS connections.
Only a few CDNs support Brotli but most do not, so on a non-Brotli CDN even if your origin server can serve Brotli, your users will not get Brotli compressed content. The table below shows which CDNs support Brotli compression.
- RFC 7932: Brotli Compressed Data Format
- Brotli on Wikipedia
- Next Generation Server Compression With Brotli (Smashing Magazine, Oct 2016)
- Brotli-G: An open-source compression/decompression standard for digital assets that is compatible with GPU hardware (AMD, Nov 2022)
CDNs and Compression
CDN → client
What is the behaviour of the CDN when sending objects to the client? Three possibilities:
- Resend from origin only: the CDN only sends compressed to the client if the customer origin server sent the object compressed to the CDN
- Compress on the edge only: the CDN fetches from the customer origin uncompressed and does the compression on the fly on the edge server
- Resend, or compress on edge: CDN fetches from origin compressed; if origin does not serve compressed, the CDN will cache the uncompressed file and do the compression on the fly before serving to clients
CDN ← origin
Can your origin serve content compressed to the CDN? This is important because some CDNs want to fetch compressed from origin and this speeds up cache miss responses. However, some CDNs always fetch uncompressed. See our table below for a CDN behaviour overview.
File types
Is your origin server and/or CDN serving all compressable content compressed? The HTML5 Boilerplate Nginx server config lists content types that should be served compressed:
View compressable content types
application/atom+xml application/geo+json application/javascript application/x-javascript application/json application/ld+json application/manifest+json application/rdf+xml application/rss+xml application/vnd.ms-fontobject application/wasm application/x-web-app-manifest+json application/xhtml+xml application/xml font/eot font/otf font/ttf image/bmp image/svg+xml image/vnd.microsoft.icon image/x-icon text/cache-manifest text/calendar text/css text/javascript text/markdown text/plain text/xml text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy
CDN comparison
CDN | CDN → client | CDN ← origin | File types | Brotli |
---|---|---|---|---|
AdvancedHosting | Resend from origin | |||
Akamai | Resend, or compress on edge | |||
BelugaCDN | Compress on edge | |||
Bunny CDN | Compress on edge | |||
CacheFly | Resend from origin | |||
CDN77 | Compress on edge | |||
CDNetworks | Resend, or compress on edge | |||
CDNvideo | Resend from origin | |||
ChinaCache | Resend, or compress on edge | |||
Cloudflare | Resend, or compress on edge | |||
CloudFront | Resend, or compress on edge | |||
EdgeNext | Resend, or compress on edge | |||
Edgio | Resend, or compress on edge | |||
Fastly | Resend, or compress on edge | |||
Gcore | Resend, or compress on edge | |||
Imperva | Resend, or compress on edge | |||
Kingsoft Cloud | Resend, or compress on edge | |||
Leaseweb | Resend, or compress on edge | |||
Lumen | Resend from origin | |||
StackPath | Resend, or compress on edge | |||
Tata Communications | Resend from origin | |||
Tencent Cloud | Resend, or compress on edge |
More info per CDN
AdvancedHosting
CDN for Static Content does not have GZip compression enabled by default.
Akamai
Akamai CDN can be configured to return pass on and cache already Brotli-compressed content from the origins. The CDN will not do the Brotli compression at the edge. More details in the good Akamai community article Brotli Support & Resource Optimizer Enablement on Akamai
Bunny CDN
bunny automatically compresses content at the edge using GZip or Brotli. How BunnyCDN shredded the size of your text files by 10-20% with Brotli
Their Support Hub lists all MIME types that are compressed at the edge: Which MIME types does BunnyCDN gzip?
CDN77
CDN77 always requests the uncompressed version of the content and will compress an object on the fly if a client requests it compressed. Customers cannot control which content types are served compressed. This is not necessarily bad but in our opinion CDN77 should serve files of more content types compressed. Their current list covers the most popular content types but why not compress e.g. application/ld+json
and font/eot
files too?
CDN77 supports Brotli and that is a good thing.
Cloudflare
Cloudflare will fetch compressed from origin and store and serve those compressed responses to the user. If your origin does not serve compressed, Cloudflare will handle that just fine by compressing the response on the edge. Cloudflare can also uncompress a response on the fly if needed. What will Cloudflare compress?.
Enterprise customers can configure which file/content types should be served compressed. By default, Cloudflare serves many file/content types compressed: What Cloudflare gzips.
CloudFront
AWS Documentation: Serving Compressed Files which includes a list of content types that CloudFront compresses
EdgeNext
By default, Gzip compression is disabled, meaning EdgeNext will not send content compressed to clients regardless of the behaviour of your origin. Enabling Gzip compression is easy and free for every customer.
If the origin sends compressed to CDN, EdgeNext will cache the compressed object and serve to eligible clients/browsers. If the origin sends uncompressed to CDN, EdgeNext will cache the uncompressed object. The EdgeNext edge server will then compress a cached uncompressed object on the fly before sending to a client/browser if the client/browser indicates it can handle compressed content and if the object is of a content type that should be served compressed.
Edgio
By default, Gzip compression is enabled, meaning Edgio will send content compressed to clients regardless of the behaviour of your origin.
If the origin sends compressed to CDN, Edgio will cache the compressed object and serve to eligible clients/browsers. If the origin sends uncompressed to CDN, Edgio will cache the uncompressed object. The Edgio edge server will then compress a cached uncompressed object on the fly before sending to a client/browser if the client/browser indicates it can handle compressed content and if the object is of a content type that should be served compressed. Customers can easily control a list of content types Edgio should serve Gzip compressed.
Tip: make sure your origin sends content compressed to Edgio. If not, cache miss responses will be slow and fat (many bytes over the wire) because Edgio does not gzip on the fly in case of a cache miss !
Files larger than 3 MB will never be served to clients compressed. Read more in the Edgio docs
Fastly
Fastly will fetch compressed from origin. If the origin does not serve compressed responses, Fastly customers can configure their service to do the compression on the edge. See: Enabling automatic gzipping and the relevant API doc. Its nice Fastly allows the customer to specify which content types or file extensions to compress.
Fastly supports Brotli. Read through the Brotli Compression Supportarticle in the Fastly Community portal to learn more.
Gcore
It is recommended to read the Content compression on CDN and Compression on the origin articles in the Gcore Knowledge Base to understand all the options for compression and how those options (don't) work together.
Imperva
Imperva supports the origin sends Brotli compressed content to the CDN but does not serve Brotli compressed content from CDN to clients
Kingsoft Cloud
If the origin sends compressed to CDN, Kingsoft Cloud will cache the compressed object and serve to eligible clients/browsers. If the origin sends uncompressed to CDN, Kingsoft Cloud will cache the uncompressed object. The Kingsoft Cloud edge server will then compress a cached uncompressed object on the fly before sending to a client/browser if the client/browser indicates it can handle compressed content and if the object is of a content type that should be served compressed. Customer requires Kingsoft's support to configure which types of content must be served compressed.
StackPath
StackPath CDN does not Brotli compress on the edge. The CDN can cache & deliver the Brotli compressed content that is served from origin to CDN, but this is not enabled by default. Read how to enable Brotli compression in this article: How to Configure Brotli Compression with the StackPath CDN/WAF
Tata Communications
Tata CDN always requests the compressed version of the content regardless of how the client request comes in. Tata CDN does not differentiate based on file size or type unless it is specifically configured to do so (customers can't tweak this self, Tata support is needed). The CDN passes along the Accept-Encoding
header from client to origin. If the origin does not send compressed to CDN, the CDN will not send compressed to clients (unless you use their Intelligent Origin Access service which costs extra).
Tencent Cloud
By default, compression on the edge is disabled but caching and serving compressed content from origin is on by default. More information is available in the Smart Compression Configuration documentation.