- Newest
- Most votes
- Most comments
For an unknown reason, the trigger for the double Brotli encoding by CloudFront stopped messing around...
Now the distribution works as expected:
- The files stored compressed on S3 are served as-is by CloudFront.
- Web browsers decode the files as expected.
Sorry for the noise...
The issue you're experiencing is likely related to how CloudFront handles file compression and content types. When you save compressed JSON files with the extension .json, CloudFront may be attempting to re-compress or modify these files, leading to the decompression issues in browsers.
CloudFront supports Brotli compression, but it's important to note that some web browsers, like Chrome and Firefox, only support Brotli compression when the request is sent using HTTPS. They don't support Brotli with HTTP requests.
The reason your files work correctly when saved with the .json.br extension is that CloudFront recognizes this as an already compressed file and doesn't attempt to modify it further.
To resolve this issue without changing your file extensions or adding CloudFront functions, you could try the following:
-
Ensure that you're using HTTPS for your CloudFront distribution.
-
In your BucketDeployment configuration, try explicitly setting the content type and encoding:
new BucketDeployment(this, 'CdnBucketDeploymentLessons', { // ... other options ... contentType: 'application/json', contentEncoding: 'br', // ... rest of your configuration ... }); -
Make sure your CloudFront distribution is configured to respect the origin's cache headers and not override them.
-
In your CloudFront distribution settings, ensure that Brotli is enabled in the cache policy.
If these steps don't resolve the issue, you might need to consider using the .json.br extension for your files, as this seems to be the most reliable way to ensure the files are served correctly without alteration.
Remember, when using pre-compressed files, it's generally better to let CloudFront serve these files as-is rather than trying to compress them again at the edge. This approach can lead to faster content delivery and less processing overhead.
Sources
Serve compressed files - Amazon CloudFront
Cloudfront not serving pre compressed .gz files from s3 | AWS re:Post
Relevant content
- asked 3 years ago
- asked a year ago
- asked 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated a year ago

This does not seem to be a CloudFront issue as accessing a
.json.brfile works while accessing the same compressed file with just.jsonfails...As I already applied the suggested configuration, I'm going to rely on the SDK to publish the compressed files for now.