In short, and as a rule with all scripts, load scripts asynchronously / non-blocking when possible, including Google +1. (function(d, t, g, s){ 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'); Load it as far up your page as possible, as to benefit from the parallelism early on and not han…
I suppose these are JS performance tricks? - Define g and s as parameter even though they're only given a value inside the function - Pass document into the function instead of using it from global scope - Insert a script tag in front of the other script tags on-the-fly using insertBefore, instead of simply doing ... Pretty interesting. Care to explain a bit?
- Define g and s as parameter even though they're only given a value inside the function
- Pass document into the function instead of using it from global scope
This is not necessarily true: javascript passed arguments by reference, and thus g and s are actually "given back" to the caller, who can then do different things with those objects.
d is not necessarily a document, but can be something different too: consider, for example, the contentWindow of an iframe.