Introduction When CDN compression is not working, static assets are served uncompressed, increasing bandwidth costs and page load times significantly.
Symptoms - Large CSS/JS file sizes in browser DevTools - Content-Encoding header missing from CDN response - Origin serves compressed but CDN serves uncompressed - Brotli not working, only gzip (or neither) - Compression working for some content types but not others
Common Causes - CDN compression not enabled in configuration - Content-Type not in CDN compression whitelist - Origin already compressing and CDN not re-compressing - Accept-Encoding header not forwarded to origin - Compressed version cached with wrong Content-Encoding
Step-by-Step Fix 1. **Check compression headers': ```bash curl -sI -H "Accept-Encoding: br, gzip" https://cdn.example.com/app.js \ | grep -i "content-encoding|vary" ```
- 1.**Enable CDN compression':
- 2.```bash
- 3.# CloudFront
- 4.aws cloudfront update-distribution --id E123 --cli-input-json '{
- 5."DistributionConfig": {
- 6."DefaultCacheBehavior": {"Compress": true}
- 7.}
- 8.}'
- 9.
` - 10.**Ensure Vary: Accept-Encoding header':
- 11.Origin must return
Vary: Accept-Encodingheader.