Enable Compression in AWS CloudFront
Text compression is a technique used to reduce the size of text-based resources. While it has many applications, one of its most popular use cases is on HTTP servers to minimize the amount of data transferred between the client and the server. This results in faster load times for web pages and is also considered a performance metric.
For example, when analyzing your website with a tool like PageSpeed Insights, you might encounter the following suggestion:
This post focuses on enabling text compression for a specific setup using AWS CloudFront and AWS S3. My personal website is hosted on AWS S3 and served through AWS CloudFront. Fortunately, CloudFront supports text compression through a simple configuration change. Official documentation.
Steps to Enable Compression
To enable compression support on CloudFront, you’ll need to update two settings:
-
Compress Objects Automatically →
true
-
Set a Cache Policy → Choose
Managed-CachingOptimized
That’s it! After these changes, check your response headers for Content-Encoding
. You should now see that CloudFront is serving compressed content:
The official AWS CloudFront documentation also explains caching strategies and TTL settings in more depth, which are worth exploring to fine-tune your configuration.