I opened the CloudFront Dashboard and clicked on the distribution ID, then clicked on the Origin tab and clicked, selected the default origin and then clicked on Edit. Tried to add "Accept-Encoding" in the 'Header Name' under Custom Origin Headers and set its value as "gzip", but it shows the following error:
com.amazonaws.services.cloudfront.model.InvalidArgumentException: The parameter HeaderValue for Accept-Encoding is not empty. (Service: AmazonCloudFront; Status Code: 400; Error Code: InvalidArgument; Request ID: 05685bb6-ca02-11e7-8a62-0b7037d34a58)
What can be done to enable gzip compression through CloudFront?
You can not configure CloudFront to cache based on Accept-Encoding
header. Quote from aws docs:
You can configure CloudFront to cache based on the value of any request header except the following:
- Accept-Encoding,
- Connection,
- ...
However, you can configure CloudFront to compress supported file types. In CloudFront console "Compress objects automatically" select Yes.
Note: Only files that have a size be between 1,000 and 10,000,000 bytes are compressed. When you use S3 or any other custom origin, CloudFront must get the response with a Content-Length
header so it can determine whether the size of the file is in the range that CloudFront compresses. If you are using S3, go to CORS configurations and add the Content-Length
header to the list of allowed headers.
If you want your origin to compress files, settings depend on the server you have running on that origin. Server should be set up to serve gzip-ed content to CloudFront with Content-Encoding: gzip
header, so it won't be compressed by CloudFront.
These are basic guidelines, but exact setting depends on your concrete configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With