How assets precompile in development environment on ruby on rails? How assets precompile in development environment on ruby on rails? heroku heroku

How assets precompile in development environment on ruby on rails?


If you want to precompile assets in development environment you can use this command:

RAILS_ENV=development bundle exec rake assets:precompile

You can precompile assets in development environment by default using config/development.rb

config.assets.debug = false

In most cases you don't need it because your development process will be more hard.


Every web application contains some images and CSS files to make it look pretty, along with some JavaScript files to handle user interaction and behavior. If assets are loading faster, the web application ought to perform better. There are many strategies to make assets load fast such as minifying, compressing (gzipping), caching etc.

In development mode, assets are served as separate files in the order they are specified in the manifest file.

This manifest app/assets/javascripts/application.js:

//= require core//= require projects//= require tickets

In the production environment Sprockets uses the fingerprinting scheme outlined above. By default Rails assumes assets have been precompiled and will be served as static assets by your web server.

During the precompilation phase an MD5 is generated from the contents of the compiled files, and inserted into the filenames as they are written to disc. These fingerprinted names are used by the Rails helpers in place of the manifest name.

For example this:

<%= javascript_include_tag "application" %><%= stylesheet_link_tag "application" %>

generates something like this:

<script src="/assets/application-908e25f4bf641868d8683022a5b62f54.js"></script><link href="/assets/application-4dd5b109ee3439da54f5bdfd78a80473.css" media="screen"rel="stylesheet" />

Note: with the Asset Pipeline the :cache and :concat options aren't used anymore, delete these options from the javascript_include_tag and stylesheet_link_tag.

The fingerprinting behavior is controlled by the config.assets.digest initialization option (which defaults to true for production and false for everything else).

Precompiling Rails Assets for Development