How do I troubleshoot issues with compressing files in CloudFront?

Last updated: 2022-06-02

I'm using Amazon CloudFront distribution to automatically serve compressed objects, but the content is not compressed in the viewer. How can I troubleshoot this?

Resolution

Check your CloudFront configuration

Check the configuration for viewers

First, get information about the detailed request headers sent by the browser by capturing the HTTP Archive (HAR). Then, confirm the following:
  • The request uses an HTTP version higher than HTTP 1.0. In lower version of HTTP, CloudFront removes the Accept-Encoding header and doesn't compress the object in the response.
  • The Accept-Encoding header is included in the viewer request and contains either the gzip or br value.

Verify the response that the origin server is returning to CloudFront

If you have access to the origin, check the response that the origin server is returning to CloudFront. Then, confirm the following:

  • The origin doesn't return a Content-Encoding header. This header indicates that the response is already compressed.
  • The response Content-Length is present in the response from the origin and is within the supported range of 1,000 bytes to 10,000,000 bytes.
  • The file type is supported for compression.
  • The response HTTP status code is either 200, 403 or 404.

If you observe a cache hit for the object, invalidate it from the cache. CloudFront doesn't compress objects that are already cached in edge locations when you turn on the compress image setting. CloudFront returns the "X-Cache: Hit from CloudFront" response when requests are served from the edge cache.


Did this article help?


Do you need billing or technical support?