title: Will inserting the same `<script>` into the DOM twice cause a second request in any browsers?
body: <p>I've been working on a bit of JavaScript code that, under certain conditions, lazy-loads a couple of different libraries (<a href="http://getclicky.com/" rel="noreferrer">Clicky Web Analytics</a> and the <a href="http://sizzlejs.com/" rel="noreferrer">Sizzle</a> selector engine).</p>
  
  <p>This script is downloaded millions of times per day, so performance optimization is a major concern. To date, I've employed a couple of flags like <code>script_loading</code> and <code>script_loaded</code> to try to ensure that I don't load either library more than once (by "load," I mean requesting the scripts after page load by inserting a <code>&lt;script&gt;</code> element into the DOM).</p>
  
  <p>My question is: Rather than rely on these flags, which have gotten a little unwieldy and hard to follow in my code (think callbacks and all of the pitfalls of asynchronous code), is it cross-browser safe (i.e., back to IE 6) and not detrimental to performance to just call a simple function to insert a <code>&lt;script&gt;</code> element whenever I reach a code branch that needs one of these libraries?</p>
  
  <p>The latter would still ensure that I only load either library when I need it, and would also simplify and reduce the weight of my code base, but I need to be absolutely sure that this won't result in additional, unnecessary browser requests.</p>
  
  <p>My hunch is that appending a <code>&lt;script&gt;</code> element multiple times won't be harmful, as I assume browsers should recognize a duplicate <code>src</code> URL and rely on a local cached copy. But, you know what happens when we assume...</p>
  
  <p>I'm hoping that someone is familiar enough with the behavior of various modern (and not-so-modern, such as IE 6) browsers to be able to speak to what will happen in this case.</p>
  
  <p>In the meantime, I'll write a test to try to answer this first-hand. My hesitation is just that this may be difficult and cumbersome to verify with certainty in every browser that my script is expected to support.</p>
  
  <p>Thanks in advance for any help and/or input!</p>