Skip Navigation

[Resolved] How to defer recaptcha script

This support ticket is created 2 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 5 replies, has 2 voices.

Last updated by Minesh 2 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2298115
recaptcha.jpg

Trying to optimise the website. Main issue is recaptcha script loaded via cred forms.
Found a solution to defer the script in one of the tickets but it does not work.

Tring to defer hidden link
It takes 2.25 seconds to load!

If I disable recaptcha - speed is back to normal.

#2298557

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Have you checked the following related ticket?
- https://toolset.com/forums/topic/i-need-to-defer-loading-the-recaptcha-script-for-optimization-purposes/#post-1823251

Have you tried the solution shared with the above related ticket or what solution you tried to use?

#2298721

I have tried exactly this solution but it does not apply defer to the script. Maybe this is different script?
As I need hidden link to be deferred.

And the sample is applied to hidden link

Thank you

#2298773

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please try to use the following code and check if that help you to resolve your issue.

add_filter( 'clean_url', function( $url ) {

    if ( FALSE !== strpos( $url, 'recaptcha__en.js' ) ) { // not our file
	  	  return "$url' defer='defer";
	}else{
		return $url;
	}
	
}, 11, 1 );

Does this helps?

#2298911

This is what it is loading
<script type='text/javascript' src='//www.google.com/recaptcha/api.js?onload=onLoadRecaptcha&render=explicit&hl=en'></script>

I have put both codes into functions. But
None of the code is working 🙁

Defer is still missing

#2298915

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

If its loading the script as you shared:

<script type='text/javascript' src='//www.google.com/recaptcha/api.js?onload=onLoadRecaptcha&render=explicit&hl=en'></script>

What if you try the following code:

add_filter( 'clean_url', function( $url ) {
 
    if ( FALSE !== strpos( $url, 'www.google.com/recaptcha/api.js' ) ) { // not our file
          return "$url' defer='defer";
    }else{
        return $url;
    }
     
}, 11, 1 );

Can you please try above, it should work, If that does not work, I will require access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.