Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.1 Static Asset - Must Assets by Precompiled for Productions?

My understanding of new Rails 3.1 asset pipeline in production mode is as follows:->

  1. config.action_controller.asset_host = "https://mybucket.s3.amazonaws.com"
  2. config.assets.compile = false
  3. app/assets are checked into repo
  4. bundle exec rake assets:precompile and sync with S3 (all assets)
  5. public/assets is NOT checked into repo

With all the above, I thought Rails would look for all the assets on S3 and I don't need them in the repository. Or at least I don't need the precompiled assets in public/assets in the repo.

I have found this, on heroku, if don't have config.assets.compile = true, it flat out will not find the precompiled assets on S3. And heroku must run through a compiling phase for all assets, but then will server them out of S3. Running heroku run rake assets:precompile doesn't do squat. The production process will re-compile everything again.

Huh? That makes no sense to me.

I would make sense to me that you do not need to fill your repo with images, let your CDN do the work.

I have a feeling this is incorrect. Am I right or wrong?

like image 265
Karl Avatar asked Sep 06 '11 18:09

Karl


People also ask

How do you Precompile rails assets?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

What does rake assets Clean do?

rake assets:clean removes compiled assets. It is run by cap deploy:assets:clean to remove compiled assets, generally from a remote server.

How does Rails asset pipeline work?

The asset pipeline provides a framework to concatenate and minify or compress JavaScript and CSS assets. It also adds the ability to write these assets in other languages such as CoffeeScript, Sass and ERB. Prior to Rails 3.1 these features were added through third-party Ruby libraries such as Jammit and Sprockets.


1 Answers

When you have this set:

config.assets.compile = false

no requests for assets will be passed to Sprockets to be served. It is expected that the files will be precompiled somewhere.

Check out the asset pipeline setup guide on the Heroku site as there is a special setup to get it working.

like image 100
Richard Hulse Avatar answered Oct 14 '22 07:10

Richard Hulse