5

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?

1

1 Answer 1

5

The async attribute is a fairly new development that isn't supported by most versions of IE. google's code is essentially a cross-browser way to emulate async.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.