title: document.createElement('script') vs <script src="">
body: <p>Why is it that services like Google and Facebook use <code>document.createElement('script')</code> instead of just <code>&lt;script&gt;</code>?</p>
  
  <p>The Google Analytics snippet:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
  document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
  &lt;/script&gt;
  </code></pre>
  
  <p>could be written as just:</p>
  
  <pre><code>&lt;script src="//www.google-analytics.com/ga.js" type="text/javascript"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>and Facebook's like button:</p>
  
  <pre><code>&lt;script&gt;(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&amp;appId=xxx";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));&lt;/script&gt;
  </code></pre>
  
  <p>could be simplified as just:</p>
  
  <pre><code>&lt;script src="//connect.facebook.net/en_GB/all.js#xfbml=1&amp;appId=xxx"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>I know there's some playing safe in them, but other than that I don't see why we shouldn't use the HTML5 ones?</p>