title: Rails Engines: shared asset dependencies
body: <p>I'm writing a mountable Rails 3.1 engine that adds features to the main app (i.e. it isn't isolated). The engine's JS depends on <a href="http://jquery.com" rel="noreferrer">jQuery</a>, <a href="http://jqueryui.com" rel="noreferrer">jQueryUI</a>, <a href="http://datatables.net" rel="noreferrer">DataTables</a> and <a href="http://www.jstree.com" rel="noreferrer">JSTree</a> (among other libraries) so the engine's manifest looks a little something like:</p>
  
  <pre><code>// my_engine.js
  
  //= require jquery
  //= require jquery_ujs
  //= require jquery-ui
  //= require jstree_pre1.0_fix_1/jquery.jstree.js
  //= require_tree .
  </code></pre>
  
  <p>I can then <em>conditionally</em> load this file into the main app's layout using:</p>
  
  <pre><code>&lt;%= javascript_include_tag 'application' %&gt;
  &lt;%= javascript_include_tag 'my_engine/my_engine' if user_logged_in? %&gt;
  </code></pre>
  
  <p>However, if the main app's manifest already includes one of the dependencies (most likely jQuery and jQuery_UJS) then those dependencies will be loaded twice. I'll see something like:</p>
  
  <pre><code>&lt;script src="/assets/jquery.js?body=1" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="/assets/jquery_ujs.js?body=1" type="text/javascript"&gt;&lt;/script&gt;
  ...
  &lt;script src="/assets/application.js?body=1" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;script src="/assets/jquery.js?body=1" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="/assets/jquery_ujs.js?body=1" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="/assets/jquery-ui.js?body=1" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="/assets/jstree_pre1.0_fix_1/jquery.jstree.js?body=1" type="text/javascript"&gt;&lt;/script&gt;
  ...
  &lt;script src="/assets/cms/application.js?body=1" type="text/javascript"&gt;&lt;/script&gt;
  </code></pre>
  
  <p><a href="http://getsprockets.com" rel="noreferrer">Sprocket</a>'s <code>require</code> directive will only require an asset once within the same bundle but here I am working with two bundles. To make it simple for other devs implementing my engine, I'd like them to be able to include one line that detects whether or not the shared dependencies are already included. Is there are nice way of doing this using Sprockets?</p>