Rails 3 automatic asset deployment to Amazon CloudFront?

后端 未结 4 1017
礼貌的吻别
礼貌的吻别 2020-12-30 09:19

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?

相关标签:
4条回答
  • 2020-12-30 09:34

    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
    0 讨论(0)
  • 2020-12-30 09:35

    Take a look at https://github.com/rumblelabs/asset_sync - we're using it just to S3 but I guess the CloudFront part is pretty easy once the assets are on S3.

    It's ends up being a rake task that you just add to execute in your deployment process.

    0 讨论(0)
  • 2020-12-30 09:39

    another option would be https://github.com/moocode/asset_id, the readme has an example to use it with cloudfront. It should work with rails 3.1 but I have only used it on 3.0.x.

    Ss John said all solutions would end up being a rake task + a bit of logic to change the asset path in rails.

    0 讨论(0)
  • 2020-12-30 09:49

    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

    0 讨论(0)
提交回复
热议问题