2

Recaptcha recommends loading of its script like this:

<script src="https://www.google.com/recaptcha/api.js" async defer></script>

I added this to the head section of the html document and checked with Chrome when it is loaded. Chrome says it is loaded before page load (the network tab of chrome devtools indicates the end of the page load with a vertical red line and the above script is loaded before that.

Why is that? Shouldn't adding async defer as recommended by google defer loading of the script after page load?

2

The page is only fully loaded when all linked resources (including <script async defer) have loaded. This is when the onload event fires.

However, the DOMContentLoaded event is likely to fire before this - which will probably be before the async defer scripts have loaded. (I say "probably" - if the browser is able to determine that it can load the script in another thread at the same time without slowing things down then I guess it probably will; but with no guarantee.)

  • My problem is I'd like to reduce the page load time. Google recommends scripts should be load asynchronously, that's why it says to use the async defer tags. But it's useless if it happens before page load, because then it is added to the page load time, which is what google measures too. – Tom May 31 '16 at 17:02
  • 1
    async defer potentially reduces the perceived page load time for the user. It reduces the time to when the document is ready. So results in a better user experience. I wouldn't be surprised if Google somehow incorporates these factors into its algorithm. We don't know for sure exactly how/what Googlebot calculates when determining page load time. – MrWhite May 31 '16 at 19:19
  • 1
    If you want to take this script completely out of the page load time (ie. after the page load event). Then only load/generate the <script> element after the page has loaded. However, Googlebot is "probably" capable of running this as well - so will still be able to determine that you are loading more resources (but whether Googlebot sees that as part of the overall load time is another matter). – MrWhite May 31 '16 at 19:26
  • "We don't know for sure exactly how/what Googlebot calculates when determining page load time" I wonder why that is. If google wants faster pages from us then it should tell us exactly what it considers page load time, shouldn't it? – Tom May 31 '16 at 19:32
  • @Tom Not necessarily. We can figure out how to load pages faster, but I don't think Google wants us to figure out how it determines what loads pages faster. Then people will just focus on and game those factors for ranking purposes. – Tim Malone May 31 '16 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.