Both the Tweet Button and Facebook Like widgets tell you to add something like this to your HTML:
<script>
!function(d,s,id){
var js,fjs=d.getElementsByTagName(s)[0];
if(!d.getElementById(id)){
js=d.createElement(s);
js.id=id;
js.src="https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js,fjs);
}
}(document,"script","twitter-wjs");
</script>
which dynamically adds a <script>
element to the DOM which then loads the actual widget JavaScript. Why is this done dynamically instead of directly loading the widget like this (which is simpler and cleaner):
<script src="https://platform.twitter.com/widgets.js"></script>
The only reason I can think of is that it defers the script load until the page has loaded, but this can just as easily be accomplished by placing the <script>
just before the </body>
close.