title: Is there a performance gain in including <script> tags as opposed to using eval?
body: <p>I have seen a lot of suggestions about how one should add code dynamically like so <a href="http://www.sanraul.com/2009/02/14/inserting-script-tags-at-runtime/" rel="nofollow noreferrer">(source)</a>:</p>
  
  <pre><code>var myScript = document.createElement("script");
  myScript.setAttribute("type","text/javascript");
  myScript.innerHTML += 'alert("Hello");';
  document.body.appendChild(myScript);
  </code></pre>
  
  <p>As opposed to <code>eval</code> like so</p>
  
  <pre><code>eval('alert("Hello");');
  </code></pre>
  
  <p>People complain about performance drops and security issues with <code>eval</code>, but I can't imagine how adding <code>&lt;script&gt;</code> tags would be any faster or any more secure. </p>
  
  <hr>
  
  <p><strong>EDIT</strong> people would like to know why I am evaling something as trivial as <code>alert("Hello")</code>, here is why: </p>
  
  <p>I have a database of, lets say, 1,000,000,000,000 scripts =P obviously I can't load every one, instead the user can load whichever they wish. The scripts are stored serverside in arbritrary locations. Currently I request (xmlhttprequest interpreted as javascript) a script via its script name and the server will find it (somehow) and return it as text, which immediately gets executed/interpreted. I want to know if it would be better to return the script as text, then create a <code>&lt;script&gt;</code> tag out of it. </p>
  
  <p>Also, this is NOT a duplicate of <a href="https://stackoverflow.com/questions/4903982/javascript-difference-between-eval-and-appending-script-tags">Javascript difference between eval() and appending script tags</a>, that deals with the functional differences, here I want the performance and security differences.</p>