-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pre-loading reCaptcha slows down site performance #22
Comments
Following the example, I did a workaround with your module in the following way...
<!-- <script src="https://www.google.com/recaptcha/api.js"></script>-->
<script type="text/javascript">
jQuery(document).ready(function (jQuery) {
jQuery.getScript("https://www.google.com/recaptcha/api.js?render=6LemGHsUAAAAAITFL13bw0ujJQuIFSpPsEbo3St7")
.done(function (script, textStatus) {
if (typeof grecaptcha !== "undefined") {
grecaptcha.ready(function () {
var siteKey = '6LemGHsUAAAAAITFL13bw0ujJQuIFSpPsEbo3St7';
jQuery('#mauticform_input_novidadesmagenteirocomlivromagenteirosite_email').click(function() {
jQuery('body').append(jQuery('<div id="captcha_container" class="google-cpatcha"></div>'));
setTimeout(function() {
grecaptcha.render('captcha_container', {
'sitekey': siteKey
});
}, 1000);
});
});
}
});
});
</script> I'm not sure if it's the best way, but now:
The thing is how to implement it in the same way inside the module. |
Update: I just improved my method a little bit more. So now everything is loaded only when the input field is focused. <script type="text/javascript">
jQuery('#mauticform_input_novidadesmagenteirocomlivromagenteirosite_email').focus(function () {
if(typeof loadedRecaptcha != 'undefined'){
return;
}
jQuery.getScript("https://www.google.com/recaptcha/api.js?render=6LemGHsUAAAAAITFL13bw0ujJQuIFSpPsEbo3St7")
.done(function (script, textStatus) {
if (typeof grecaptcha !== "undefined") {
grecaptcha.ready(function () {
var siteKey = '6LemGHsUAAAAAITFL13bw0ujJQuIFSpPsEbo3St7';
jQuery('body').append(jQuery('<div id="captcha_container" class="google-cpatcha"></div>'));
setTimeout(function() {
grecaptcha.render('captcha_container', {
'sitekey': siteKey
});
}, 1000);
});
}
loadedRecaptcha = true;
});
});
</script> Just need to keep in mind everything else I said in the previous comment. |
Hi Konstantin. First of all thanks for this great work. It saved us from indefatigable spam bots.
I'm wondering if we can find a way to load reCaptcha on demand. I have a site where I have a sign in form in all fages, and now I'm loading reCaptcha.
It slowed down the page speed in all page metrics due to multiple requests and recaptcha css.
Do you know if/how we can implement one of these solutions here?
https://stackoverflow.com/questions/35245768/load-recaptcha-dynamically
Thanks in advance.
The text was updated successfully, but these errors were encountered: