Thalatta
Thalatta

Reputation: 4578

How to Host Rails Assets Through a CDN without pushing assets to Heroku

So I currently have too many assets to push to my free heroku account. I am currently hosting them on a hostgator server which is problematic as, by making a remote request for each image, and the server itself not being of the nature of say Amazon CloudFront which expedites and caches things explicitly for CDN, it visibly loads all the images all slow-like in the DOM. My question is, how can I serve my assets through CloudFront without pushing them to my heroku account?

Upvotes: 0

Views: 422

Answers (1)

nort
nort

Reputation: 1615

The best solution is to create a custom deployment script that has a step specifically for uploading your assets to S3, then serve the assets from S3 via CloudFront.(have a look at https://github.com/rumblelabs/asset_sync for ideas)

Specifically:

  1. Add your assets to your .gitignore
  2. Set your asset host correctly in your production.rb file
  3. Step 1 in deploying is copy changed assets to your S3 bucket in the same folder structure that rails expects
  4. Step 2 in deploying is your push to repo with the standard command git push heroku master -- which will not push your assets if they are ignored correctly.

Upvotes: 1

Related Questions