On the "Google+ Sign-In for server-side apps" help page, in "Step 3: Include the Google+ script on your page" the following snippet is suggested:
<!-- The top of file index.html -->
<html itemscope itemtype="http://schema.org/Article">
<head>
<!-- BEGIN Pre-requisites -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
</script>
<script type="text/javascript">
(function () {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://plus.google.com/js/client:plusone.js?onload=start';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
</script>
<!-- END Pre-requisites -->
</head>
<!-- ... -->
Now, what the second SCRIPT seems to do:
- create a new SCRIPT tag, with static source
- insert it immediately, before the first SCRIPT tag in the file.
Now, my question is WHAT FOR? I mean, wouldn't doing:
<!-- The top of file index.html -->
<html itemscope itemtype="http://schema.org/Article">
<head>
<!-- BEGIN Pre-requisites -->
<script async src="https://plus.google.com/js/client:plusone.js?onload=start"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<!-- END Pre-requisites -->
</head>
<!-- ... -->
achieve the same thing? Why this extra wrapper function inserting the script?
async
attribute has support issues. It won't work on IE<=9. See stackoverflow.com/questions/1834077/…