I'm working on a Rails app with a high number of assets, which sadly cannot be reduced. In production this is not a problem, but in development, ~20 asset requests per visited page cannot be quickly served by an application server (like webrick or Thin).
So I started using nginx in development for serving anything in public/assets
. Note that nginx is purely a development facility - we don't intend to use it in production.
For it to work I just had to do two things:
config.assets.debug
to falserake assets:precompile
Sadly there are two problems (the latter being the most important one) with my setup:
rake assets:precompile
againWhat is a correct nginx / Asset Pipeline setup which does not require a Rails server restart after precompilation?
Automatic compilation would also be welcome.
This setup worked for me:
config.asset_host
config.assets.debug = false
config.assets.digest = true
config.assets.compile = true
rm -rf public/assets; rake tmp:clear tmp:cache:clear assets:clean assets:precompile
rake assets:precompile
again. Guard can take care of that.This may require a lot of effort but consider switching to gulp or grunt in order to compile assets. Using node js can speed up the process significantly (a lot of articles on it, here is an example one http://blog.carbonfive.com/2014/05/05/roll-your-own-asset-pipeline-with-gulp/). And what is also important assets may be compiled without server restart (process triggered on file change [hooks]). In project I'm involved one of our guys is trying to make this kind of switch, and from what he says I understand it's not a one-day task.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With