title: JavaScript dependency injection via dynamic <script> tag
body: <p>Using JSONP in vanilla JavaScript via creating a <code>&lt;script&gt;</code> tag with a <code>src</code> led me to consider using that same method for dependency injection in JavaScript plugins and other JavaScript components that utilize libraries but want to be as independent as possible.</p>
  
  <p>Using jQuery as an example of a popular library that could potentially need to be injected...</p>
  
  <pre><code>// make sure we don't load it if already loaded.
  if (typeof jQuery === 'undefined') {
      var dependency = document.createElement('script');
      dependency.src = "https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js";
      document.getElementsByTagName('head')[0].appendChild(dependency);
  }
  
  window.onload = function() {
      // jQuery is now available w/o the extra &lt;script&gt; tag added by the end user...
  }
  </code></pre>
  
  <p>Really at this point it's mainly conceptual (<em>but does work</em>), but I'm wondering if this would be considered a acceptable solution for JavaScript dependency injection? Any thoughts on this?</p>