Skip to content

Cloudfront not serving pre compressed .gz files from s3

0

Hi everyone,

I am deploying my Static Next js application to S3 and then serving ti via Cloudfront.

I am uploading to s3 both html files and html.gz files. When I upload the gz files I am making sure to set the metadata header via --content-encoding. I can see both html and html.gz being in my s3 with the right tags.

if i hit /index.html.gz i correctly get a zipped content. But what I would expect is cloudfront to automatically serve the .gz version when hitting index.html. but this is not happening .

What am I missing?

compression is not set to true as I am pre compressing the files.

asked 2 years ago982 views

2 Answers
2
Accepted Answer

Hi,

the right way to proceed is to NOT compress yourself at origing but configure CloudFront to compress at edge for the types of files for which compression is interesting.

See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html

This way, when you hit a file from index.html, you will click the link corresponding to uncompressed version but Cloudfront will compress it at edge (if there is not already a compressed version in cache) and serve the compressed version (which will be automatically decompressed by the receiving browser if configured to do so),

Best,

Didier

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

  • Thank Didier, I did that now works.

  • Hi Vanals, glad that your issue is now fixed! Thanks for accepting my answer

0

According to the documentation here, I think you do want to enable compression. https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/ServingCompressedFiles.html

"If the origin returns a compressed object, as indicated by the presence of a Content-Encoding header in the HTTP response, CloudFront sends the compressed object to the viewer, adds it to the cache, and skips the remaining step. CloudFront doesn’t compress the object again."

Hope this helps!

AWS

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.