I use an Amazon CloudFront distribution to automatically serve compressed objects, but the content isn't compressed in the viewer.
Resolution
Check your CloudFront configuration
Take the following actions:
Check the configuration for viewers
First, capture the HTTP Archive (HAR) to get information about the detailed request headers sent by the browser. Then, verify that the Accept-Encoding header is included in the viewer request and contains gzip or br or both. The request must use an HTTP version higher than HTTP 1.0. In lower versions of HTTP, CloudFront removes the Accept-Encoding header and doesn't compress the object in the response.
Check the response that the origin server returns to CloudFront
If you have access to the origin, then check the response that the origin server returns to CloudFront. Check for the following requirements:
- The origin doesn't return a Content-Encoding header. This header shows that the response is already compressed.
- Content-Length is in the response and is within the supported range of 1,000 bytes to 10,000,000 bytes.
- The file type is supported for compression.
- The HTTP response status code is either 200, 403 or 404. For more information, see HTTP response status codes on the MDN Web Docs website.
If you see a cache for the object, then invalidate the object from the cache. CloudFront doesn't compress objects that are already cached in edge locations when you turn on the Compress image setting. If the request is served from the edge cache, then CloudFront returns the "X-Cache: Hit from CloudFront" response.
Note: CloudFront compresses objects on a best-effort basis. On rare occasions, CloudFront might skip compression.