I prefer not to concatenate JavaScript files in development mode, but serve them as individual files. So I configured:
development.rb:
config.assets.compress = false
config.assets.debug = true
config.assets.compile = true
In my /app/assets/javascript directory I have:
reviews.js:
//= require jquery
//= require jquery_ujs
//= require_tree ./reviews
I include the JavaScript using <%= javascript_include_tag "reviews" %>
in my layout. The generated page correctly references the three scripts individually and reviews.js
is essentially empty. So far so good.
Now when I precompile my assets for production using rake assets:precompile
the three JavaScript files are concatenated into reviews.js
. This is all fine for production but now, in development mode, the concatenated reviews.js
is served in addition to the two individual files.
Of course, this leads to all kinds of nasty bugs when developing because now, the content of foo.js
and bar.js
is served twice, one of them in a potentially older version in reviews.js
.
How can I make sure Rails doesn't use the precompiled assets in development mode?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…