4

Every time I pull code into my repository after making changes to JS or CSS files, I run the following commands:

rake assets:clean
rake assets:precompile

I've got quite a bit of assets, so this process always takes at least a minute. Is there any way to get it to go faster? For example, if I've only changed CSS, is there a way to tell it to only focus on CSS files and not to bother cleaning and precompiling JS?

Edit: Oops, I should have specified that this is on production. I'm aware I don't need to precompile assets on development :)

NudeCanalTroll
  • 2,266
  • 2
  • 19
  • 43

2 Answers2

3

I am assuming that you are running Rails >3.1.

Don't run the rake tasks at all. Rails development mode doesn't need the assets to be precompiled. Rails will automagically compile the assets when there is a change else it will not.

If you are looking for performance while serving assets in development you can look the gems such as https://github.com/wavii/rails-dev-tweaks

Aj Gu
  • 1,509
  • 9
  • 12
  • Just edited my question to specify that I'm trying to speed up asset precompilation for *production*. Thanks for the link, though, looks like that'll be helpful when coding in the development environment. – NudeCanalTroll Feb 08 '12 at 23:49
  • When do you compile your assets when deploying or when the first request is served? Either cases it will be slow. Most of the people who are bothered by slow compilation time generally compile the assets in development machine and push the compiles assets into production server as a shortcut. – Aj Gu Feb 08 '12 at 23:55
  • I'm compiling right after deploying. I assume if I compiled locally, it'd be just as slow ad compiling on the server? – NudeCanalTroll Feb 09 '12 at 00:00
  • Usually its not slow on development machines. I am not sure about the exact reason. You can give it a try and see if its faster or the same using 'bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile'. If this approach is faster you can also look at 'https://github.com/dnagir/guard-rails-assets' gem for automatically compiling assets for production – Aj Gu Feb 09 '12 at 00:05
0

This an add-on not pretending to be an answer.

Process monitor in Windows shows that ruby.exe makes cycles while doing assets:precompile and in each cycle it queries all the gems installed again and again.

Rails 3.2.1

Paul
  • 25,812
  • 38
  • 124
  • 247