UPDATE: Amazon now supports gzip compression, so this is no longer needed. Amazon Announcement
Original answer:
The answer is to gzip the CSS and JavaScript files. Yes, you read that right.
gzip -9 production.min.css
This will produce production.min.css.gz
. Remove the .gz
, upload to S3 (or whatever origin server you’re using) and explicitly set the Content-Encoding
header for the file to gzip
.
It’s not on-the-fly gzipping, but you could very easily wrap it up into your build/deployment scripts. The advantages are:
- It requires no CPU for Apache to gzip the content when the file is requested.
- The files are gzipped at the highest compression level (assuming
gzip -9
). - You’re serving the file from a CDN.
Assuming that your CSS/JavaScript files are (a) minified and (b) large enough to justify the CPU required to decompress on the user’s machine, you can get significant performance gains here.
Just remember: If you make a change to a file that is cached in CloudFront, make sure you invalidate the cache after making this type of change.