Is there difference between these two async JavaScript loading methods?
<div class="g-plusone"></div>
<script type="text/javascript">
(function(d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.async = true;
g.src = 'https://apis.google.com/js/plusone.js';
s.parentNode.insertBefore(g, s);
})(document, 'script');
</script>
<script type="text/javascript">
//<![CDATA[
(function() {
document.write('<fb:like href="http://www.sandrophoto.com/' + location.pathname + '" send="true" width="360" show_faces="false" font=""></fb:like>');
var s = document.createElement('SCRIPT'),
s1 = document.getElementsByTagName('SCRIPT')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://connect.facebook.net/en_US/all.js#xfbml=1';
s1.parentNode.insertBefore(s, s1);
})();
//]]>
</script>
These two look conceptually similar in loading. They both create a new script tag and add it to the DOM which allows both to load asynchronously without dependencies on other script tags which must load in the order presented. There are minor differences in these implementations, but they look conceptually the same from the loading point of view.
The document.write() in the FB code causes some serialization with other loading events and could slow it down slightly (depends upon circumstances).