I'm going to start a rich client-side web application with Ruby on Rails 3.2. I intended to use RequireJS, but it seems to collide with the Asset Pipeline. As far as I know, what the latter basically does is concatenating dependent assets, minifiying and compressing them (correct me if I'm wrong), which does not seem very compatible with loading JavaScript files asychronously.
At a first glance, the Asset Pipeline seems to have much better performance. However, RequireJS lets you organize the JavaScript code in modules easy to reuse and mange its dependencies.
Is there any way to combine both of them? In case there isn't, which one would you choose?
You might want to have a look at this gem https://github.com/jwhitley/requirejs-rails/
Seems to be doing what you want - which is to use requirejs for loading client side while still taking advantage of some of the asset pipeline.
I would be tempted to suggest that I guess that in most cases the asset pipeline would be much faster as it loads a single minified js resource. The dependency management isn't as good though, so it would very much depend on the app.
I would suggest to download the RequireJS library and toss it to vendor/assets/javascripts
. Then in your application.js
file :
//= require require
(funny , yes?) , and that should be enough.
This is the easiest way to combine the asset-pipeline and a modular js library . I am not aware of any additional settings this particular library needs , but you can take a look at this Railscast , which describes something similar.
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