Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 automatic asset deployment to Amazon CloudFront?

Is there a gem or method available in Rails 3.1 that can upload assets to amazon cloud front automatically and use those instead of serving locally hosted ones? I guess it's easy to upload compiled assets manually and then change the rails app config to use that asset host, but when an asset is modified, the uploads to cloud front would need to be done manually again. Any good ways out there for this?

like image 271
user1049097 Avatar asked Dec 02 '11 09:12

user1049097


2 Answers

Definitely check out asset_sync on github. Or our Heroku dev centre article on Using a CDN asset Host with Rails 3.1 on Heroku.

There is quite a big performance improvement in using asset_sync vs a CDN custom origin, letting your application lazily compile assets in production or serving them precompiled directly off your app servers. However I would say that. I wrote it.

  • With asset_sync and S3 you can precompile assets meaning all the assets are there ready to be served on the asset host / CDN immediately
  • You can only require the :assets bundle in application.rb on precompile, saving memory in production
  • Your app servers are NEVER hit for asset requests. You can spend expensive compute time on, you know. Computing.
  • Best practice HTTP cache headers are all set by default
  • You can enable automatic gzip compression with one extra config
like image 74
David Rice Avatar answered Oct 25 '22 03:10

David Rice


If you use Cloudfronts “Custom origin” option you do not need to upload anything, Cloudfront will fetch the assets from your server when needed. For details of setting this up see:

http://blog.ertesvag.no/post/10720082458

like image 43
Roger Ertesvag Avatar answered Oct 25 '22 04:10

Roger Ertesvag