4

Inclusion of Google's 'invisible recaptcha' seems to be massively increasing the 'First interactive' (and subsequently 'consistently interactive') times as measured by Lighthouse.

I set up two empty webpages using an HTML5 boilerplate template. These sites differ only by the inclusion of the recaptcha API script; namely, this line:

<script src='https://www.google.com/recaptcha/api.js'></script>

The first (non-recaptcha) site receives a first interactive time equivalent to the first meaningful paint time. non-recaptcha

The second (recaptcha) site gets a first interactive time of ~14 seconds, and an estimated input latency time of ~1.6 seconds:

recaptcha

I included the script at the bottom of the <head> section as indicated in Google's instructions, however I've also tried including the script at the bottom of the <body> (as well as with async and defer) with no noticeable improvements.

Is this a problem with the way Lighthouse is measuring first interactive (especially considering it's still marked as 'beta') or Recaptcha? If the latter case, is this something to be worried about, and if so are there ways to mitigate the impact?

Andrew Keller
  • 3,198
  • 5
  • 36
  • 51

1 Answers1

3

This was bothering me for some time too and this is the best solution I come up with:

  1. Do not load api.js (render captcha) script initially. This is important, as combined with [2] creates relatively huge interactive time slowdown.
  2. Do not bind the captcha to any element initially, just "prepare" it in a function for later.
  3. Now, this is the most important (clever) part - when your user starts interacting with the form, inject the api.js (recaptha__..js) script into the header, browser will load it, and trigger the binding function to load the actual captcha.

You can find more information and explanation with some code examples here: https://tehnoblog.org/google-invisible-recaptcha-how-to-boost-lighthouse-performance-score/

dev101
  • 1,359
  • 2
  • 18
  • 32
  • 1
    Sorry about that, came to this after googling for recaptcha v3 and thought the question was about that version – jontro Aug 07 '19 at 18:06
  • 1
    @jontro Ok, no problem ;) I have "edited" the answer so you can remove your downvote if you like. – dev101 Aug 07 '19 at 18:27