This document discusses best practices for loading the reCAPTCHA script tag. This information is applicable to both reCAPTCHA v2 and v3.
Loading reCAPTCHA asynchronously
All versions of the reCAPTCHA can be loaded asynchronously. Loading reCAPTCHA asynchronously does not impact its ability to identify suspicious traffic. Due to the performance benefits of asynchronous scripts, loading reCAPTCHA asynchronously is generally recommended.
In some situations, adjusting script ordering can be enough to prevent race
conditions. Alternatively, you can prevent race conditions by including the
following code snippet on pages that load reCAPTCHA. If you are using
grecaptcha.ready()
to wrap API calls, add the following code snippet to ensure
that reCAPTCHA can be called at any time.
As an alternative, sites that use the v2 API may find it useful to use
the onload
callback; the onload
callback is executed when reCAPTCHA finishes
loading. The onload
callback should be defined before loading the reCAPTCHA
script.