简体   繁体   中英

Rails asset pipeline workflow when there are hundreds of asset files

We recently converted a Rails 3.2 project to use the asset pipeline. Our app uses many asset files (~250 *.js.coffee files, another 200 or so *.jst.hamljs templates, and ~100 *.css.sass stylesheets). As you'd expect, these are packaged into a much smaller number of asset files in production.

In development and test environments, we deal with frequent timeouts and slow page-loads while recompiling and requesting individual assets. Is there a better workflow that still allows automatic recompilation?

We're running with default environment settings, except have set debug to false in development:

config.assets.debug = false

This saves us hundreds of requests when reloading the page in development, but initial compilation still causes timeouts. There must be a better way, right?

Some options:

  • Limit what is required to be recompiled when requested via use of require_asset . See this question and Sprockets #90 .

  • Precompile assets:

     $ RAILS_ENV=development bundle exec rake assets:precompile 
  • Increase timeouts. This depends on how you have things setup and can be painful and problematic, eg Heroku is not a big fan of long requests .

  • Use a faster interpreter.

  • Faster hardware/VM.

Are you precompiling the assets in development?

bundle exec rake assets:precompile

That should keep the assets from recompiling each time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM