In some of our Rails views, we have javascript functions that load certain data asynchronously to populate the page. Our application.js file loads all javascript in the assets/javascripts folder.
Here is a bit that's in one of our haml views:
:javascript
$(function() {
fetch_all_facebook_invitees();
});
If we put the fetch_all_facebook_invitees function definition in a coffeescript file, it's loaded on every page because they're included in all pages of the application:
//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .
What's the best practice to loading javascript for a page? Only doing it selectively and not load the entire tree?