Skip to content

CloudFront Not Compressing `main.js` File in AWS CDK Deployment

0

Hello AWS Community, I am facing an issue with my AWS CDK deployment where CloudFront is compressing and caching all the build files except for the main.js file.

### Steps Taken:

  1. S3 Bucket Contents: Verified that both main.js and main.js.br are present in the S3 bucket.
  2. CloudFront Configuration: Ensured that CloudFront is configured to compress files (compress: true).
  3. S3 Bucket Permissions: Verified that the S3 bucket policy allows CloudFront to access both the original and compressed versions of the files.
  4. Cache Invalidation: Invalidated the CloudFront cache to ensure that the latest versions of the files are being served.

### Issue: Despite these configurations, the main.js file is not being compressed by CloudFront, while other files are being handled correctly.

### Request: Is there any solution or additional configuration required to ensure that CloudFront compresses the main.js file along with the other build files?

Thank you for your assistance!

1 Answer
0

It may happen occasionally that a file cannot be compressed, and in that case, the uncompressed file pulled from the origin is cached and served to users until it's no longer present in the cache. When the uncompressed file is removed from the cache, a new attempt will be made to compress the file when it's pulled from the origin again.

Also, if you read the file via CloudFront before you enabled compression, the uncompressed file pulled into the cache would continue to be served to users in the same manner, although the cache invalidation you mentioned having done would've evicted that uncompressed copy.

The best-effort nature of the compression feature is explained in this documentation article: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html#compression-skipped

EXPERT

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.