google / recaptcha

PHP client library for reCAPTCHA, a free service to protect your website from spam and abuse.
http://www.google.com/recaptcha/
BSD 3-Clause "New" or "Revised" License
3.48k stars 777 forks source link

Recaptcha v2 js loads multiple times #335

Closed farley1122 closed 5 years ago

farley1122 commented 5 years ago

Issue description

recaptcha__en.js loads multiple times on any page using recaptcha v2. This is a small issue when trying to optimize page speed, as with all the reloads it comes to 270KB.

Environment

Tested on multiple production, staging, and locally hosted servers using wordpress.

Reproducing the issue

https://patrickhlauke.github.io/recaptcha/

open network tab and see that the js loads multiple times.

luisfranco commented 5 years ago

It can be replicated on their own demo as well: https://recaptcha-demo.appspot.com/recaptcha-v2-invisible.php

And, not only the recaptcha__en.js file is being loaded several times, but also their fonts: Screenshot 2019-10-30 11 44 00

JS: Screenshot 2019-10-30 11 44 23

jasonfedor commented 5 years ago

reCAPTCHA runs in multiple different frames, which requires resources to be loaded in each. This file is cached heavily though so should require <= 1 network call to load assuming caching is turned on.

andcha commented 4 years ago

@jasonfedor regardless of that, it is wrong for someone looking to improve pagespeed score. Even adwords campaigns are costlier when page load speed in slow.

On one hand google pagespeed complains of reducing number of request and here recaptcha is unnecessarily adding an extra request for same file.

One request is being initiated by https://www.google.com/recaptcha/api.js and another by https://www.google.com/recaptcha/api2/anchor

If anyone finds any workaround to this mess then please post here.

sgomes commented 3 years ago

This file is cached heavily though so should require <= 1 network call to load assuming caching is turned on.

@jasonfedor This is no longer true now that Chrome implements triple-keyed cache partitioning. The resource will now be downloaded multiple times, because the various iframes don't share a cache. And it won't be cached between origins either, so it will be re-downloaded it for every site that's visited.

This can be easily verified in Google's own demo page: https://www.google.com/recaptcha/api2/demo

I believe this warrants reopening this issue.

digiage commented 3 years ago

Please do something with that. In addition to the multiple requests for js the reCaptcha stuff consume 15 to 28 requests on my sites (the higher number may be because I use 2 reCaptchas?). That is real #perfmatters

mandys commented 3 years ago

This is actually an issue for us too. Multiple loads ( both for js and css ) and lowering of page score.

polterguy commented 1 year ago

And, the JS isn't even minified. This is quite frankly a disaster ... :/

uplink42 commented 1 year ago

Are there any plans on fixing this, or at least a workaround? We have a landing page with multiple forms (newsletters, contact us, registration etc) and all those recaptchas pile up quicky and aren't cached.

Twansparant commented 1 year ago

Yeah I've got the same issue, some of our pages have multiple forms and therefore this script is also loaded multiple times: https://www.gstatic.com/recaptcha/releases/xxxxxxxxxxxxxx/recaptcha__en.js This is causing a lower grade on performance scans like GTmetrix.

stefanosalvucci commented 1 year ago

same issue here

Giuse69 commented 1 year ago

same issue here

khalilgharbaoui commented 1 year ago

same!

JaniKowalski commented 1 year ago

Same issue!

brettrobertson61 commented 1 year ago

Same issue, Page Speed Insights complains about the 587k of render blocking JS.

JPCodeCraft commented 8 months ago

2024 and still loading 3 times and taking up 600KB of download!

I'm using it via Firebase provideAppCheck

image

parisambush commented 3 months ago

I'm having this issue too. My site is on shared hosting with limited resources, and this causes the pages that have captcha to take a very long time to load. This needs to be fixed!