Rails 3.1 Pipeline - Exclude Javascript File

I realize this is an old question, but Google sent me here last week so it's not an obsolete question. The answer I found elsewhere was the "stub" directive for sprockets. So something like

//= require-tree .
//= stub Modernizr

This keeps Modernizr.js out of the bundled assets. It can be included with its own tag, à la the original answer.

The Sprockets changelog says "stub" was added in January 2012, so it wouldn't have been available at the time this question was first answered, but I think it's a good answer now.


I chose to keep the sprockets functionality by changing

//= require_tree

to

//= require_directory .

This keeps sprockets auto-loading any files in the same directory, but not in any folders further.

This allowed me to move Modernizr.js to the assets/javascripts/top folder and manually load it at the top with:

<%= javascript_include_tag "top/modernizr" %>

and move

<%= javascript_include_tag "application" %>

To the bottom of my application.html.erb file (above the closing body tag)