grecaptcha.render.To delay the loading of Google's reCAPTCHA code only when a user reaches the form (and avoid loading it site-wide at initial load time), you can implement a conditional lazy-loading strategy in Webflow using custom code.
data- attribute on the form element.grecaptcha.render.
your-site-key-here with your real site key):
<script>
// Only run this script when the DOM is ready
document.addEventListener("DOMContentLoaded", function() {
let loaded = false;
// Target your form container or reCAPTCHA div
const target = document.querySelector('#recaptcha-wrapper');
if (target) {
const observer = new IntersectionObserver(function(entries) {
if (entries[0].isIntersecting && !loaded) {
loaded = true;
// Load the reCAPTCHA script
const script = document.createElement('script');
script.src = "https://www.google.com/recaptcha/api.js?onload=onRecaptchaLoad&render=explicit";
script.async = true;
script.defer = true;
document.body.appendChild(script);
}
}, { threshold: 0.1 });
observer.observe(target);
}
// Function to render the reCAPTCHA after script loads
window.onRecaptchaLoad = function() {
grecaptcha.render('recaptcha-wrapper', {
sitekey: 'your-site-key-here'
});
};
});
</script>
div) with ID recaptcha-wrapper where the reCAPTCHA will appear.grecaptcha.render.
To delay Google's reCAPTCHA code in Webflow and load it only on form pages when the form is visible:
grecaptcha.render when the user scrolls to the form.