Here are the general goals I had when using the rails asset pipeline :
- most of js compiled in a single file
- sometimes, I want some js code to be only explicitly included by some particular pages (example: hooking a timer on the document ready event of a particular html page). This means that I cannot simply compile all js code in a single minified file
- In unit tests, I want to be able to manually set up and tear down the js hooks
So, here is how I eventually organized my js code :
- I create a specific dependencies.js file that will require all outside dependencies
- I split my js code under 3 subdirectories :
- explicit : hooks that will be explicitly included
- hooks : all the other hooks
- application : all the real code
//= require dependencies.js //= require_tree ./application //= require_tree ./hooks
describe 'mesCourses.cartLines.index', -> beforeEach -> window.mesCourses.cartLines.index.setUp() ...
And you, how are you organizing your javacript assets ?