Rails 3.2 + Heroku + S3 + CloudFront: does not serve gzip css js

I am running Rails 3.2 using assets_sync.

Created version of gss css and js. CloudFront does not service the gzip version, although a header is requested for gzip, deflate.

I also tried config.gzip_compression = true in asset_sync.rb , but CloudFront is still serving the uncompressed version. I have confirmed that I can access ABC.cloudfront.net/XYZ.css.gz

+8
ruby-on-rails amazon-s3 amazon-cloudfront gzip heroku
source share
2 answers

Is the S3 bucket a source for your CloudFront distribution? If so, the problem is that S3 does not properly handle the Accept-Encodings header: https://github.com/rumblelabs/asset_sync/issues/153

There are several possible solutions to this issue. You can either port gzipped files by default, as most browsers (with the exception of some mobile browsers) will handle this correctly, or you will try the solution described here .

Another possible solution is to use the Varnish cache level as a normal origin for your CloudFront distribution:

Internet → CloudFront → Lac → S3 Bucket

Once the request arrives at CloudFront, it will be redirected to Larnish if it has not already been cached in CloudFront. Larn grabs the uncompressed file from the S3 Bucket, compresses it as the headers dictate, and sends the file back to CloudFront for caching.

+4
source share

Have you set heroku config:add ASSET_SYNC_GZIP_COMPRESSION=true for your application?

+1
source share

All Articles