Skip to main content

CloudFront: Enable Automatic Compression

Difficulty: Easy

Description

Compression is turned off on at least one cache behavior of these distributions. Once it's on, CloudFront compresses text files (HTML, CSS, JavaScript, JSON, SVG, fonts) with Gzip and Brotli before sending them, which cuts data transfer at no extra cost. The saving shown is a conservative estimate on data transfer only. After you turn it on, we measure the real saving from your traffic. Distributions that mostly serve images or video will gain little.

Selection Criteria

  • The distribution is enabled.

  • At least one cache behavior on the distribution has automatic compression (Compress) turned off.

  • The distribution has a data-transfer-out cost in the last 31 days.

Expected Saving

Compression reduces the size of compressible text objects by 65–80% (JS ~77%, HTML/CSS ~70–80%, JSON ~70–85%). The reduction on your total DTO bill is smaller, because it applies only to the compressible share of your traffic — images, video, audio, and other already-compressed formats don't benefit. In practice:

  • Text-heavy distributions (web apps, APIs, static sites): roughly 30–45% off DTO once you blend compressible and non-compressible bytes.

  • Media-heavy distributions (images, video): little to no change, since most bytes aren't compressible.

Example: a distribution serving ~10 TB/month of typical mixed web traffic (HTML, JS, CSS, JSON alongside images) could save on the order of $3,000–$4,000/year — a ~30–40% reduction on its DTO. Every byte saved maps directly to a lower bill, and the change happens at the CloudFront edge with no origin work, making it one of the lowest-effort CloudFront optimizations available.

Note: AWS itself frames this conservatively — charges may drop "depending on the proportion of compressed to uncompressed requests." Your actual result tracks your content mix.

Operational Impact

  • ✅ No downtime required — enabling compression is a configuration change that takes effect within minutes of distribution deployment.

  • ⏳ Not retroactive — CloudFront compresses objects as they're (re)fetched from the origin, not the copies already sitting in the edge cache. Existing cached objects compress as they expire and refresh, or immediately if you invalidate them, so the bill drop ramps in rather than appearing instantly.

  • ⚠️ Pre-compressed origins — if the origin already sends Content-Encoding (e.g. gzip), CloudFront serves that as-is and won't re-compress. No conflict, but no additional benefit from this setting either.

  • ⚠️ Size limits — CloudFront only compresses objects between 1 KB and 10 MB (1,000–10,000,000 bytes). Smaller files and already-compressed formats (JPEG, PNG, MP4, ZIP, PDF) are excluded.

  • ⚠️ Content-Type is AWS-defined, not configured — CloudFront compresses a fixed list of content types matched against the Content-Type response header from your origin; you can't add to that list in the cache policy. What you do control: make sure your origin sets correct Content-Type headers, and that the cache policy enables both Gzip and Brotli.

  • ⚠️ Brotli prerequisites — Brotli requires a cache policy (not legacy cache settings), and browsers only negotiate Brotli over HTTPS; Gzip covers the rest.


References

Did this answer your question?