recaptcha icon indicating copy to clipboard operation
recaptcha copied to clipboard

Reduce widget payload

Open rowan-m opened this issue 5 years ago • 35 comments

Address opportunities to improve the overall loading time and bandwidth cost of the widget, specifically:

  • Seemingly 3 transfers of recaptcha__en.js at ~90KB per time
  • Coverage reports at ~73% unused
  • Logo is 2.3KB PNG, would this be better as inline SVG?

Any other thoughts? @addyosmani @khempenius re: https://twitter.com/JamesWee_/status/1169760386834284545

rowan-m avatar Sep 06 '19 09:09 rowan-m

Would love to see if we can get some eyes on the largest offenders here (script costs). I'm curious if it's possible to break down the user-flows here into distinct on-demand loading steps (e.g lean core, minimal script for the "I am not a robot" flow, only load script for the more complex verification steps as needed..)

addyosmani avatar Sep 06 '19 14:09 addyosmani

I would also love to see some resolution to this issue. Right now, 3 of the same scripts at 90kb each, is accounting for around 7-12% of each of the pages on the site I'm building (289kb total recaptcha/1.4MB total page assets). Justifying that to kind of load increase is tough when I've spent days setting up image optimization and caching, and minifying files.

thestereoscopics avatar Oct 22 '19 23:10 thestereoscopics

Hi @thestereoscopics - This is on our radar (I was actually just talking about this yesterday). However, it’s is a busy time of the year, so it’s going to be a little bit longer until we can get this prioritized (unfortunately).

khempenius avatar Oct 23 '19 16:10 khempenius

How can this not be a priority? We're trying to speed up our pages to please google audit tools etc., and get this slap to the face from google itself. Almost everything is loaded double, and the file sizes are not small...

image

Frickin 600 KB gzipped...

briedis avatar Nov 19 '19 14:11 briedis

Any update on this item?

heipei avatar Dec 19 '19 22:12 heipei

I'm not a part of the Chrome team but I did a little audit, out of curiosity, to see how other things than code splitting, as suggested by @addyosmani, could lower the widget payload.

Opportunity KB saved
Enable Brotli compression where possible (In comparison to GZIP) Brotli compression results in:
• 21% smaller HTML
• 17% smaller CSS
• 14% smaller JS
Enable Conditional Requests (Last-Modified and/or ETag) for
https://www.google.com/recaptcha/api.js

0.57 [1]
Minify <iframe> HTML resources:
https://www.google.com/recaptcha/api2/anchor?{...}
https://www.google.com/recaptcha/api2/bframe?{...}

1.12 (before GZIP)
1.07 (before GZIP)
Compress PNG (from 91.3 KB to 41.2 KB) :file_folder: bg-png.zip 50.1
Convert [2] base64 encoded images to PNG and compress (from 135.43 KB data URI to 31.37 KB PNG) :file_folder: bg-base64-to-PNG.zip 104.06
Compress JPG (from 17.4 KB to 8.62 KB) :file_folder: bg-jpg.zip 8.78
Convert photography images from PNG to JPG and compress (from 63.6 KB to 21.7 KB) :file_folder: bg-png-photos-to-jpg.zip 41.9

[1]: Payload may accumulate depending on the amount of navigations (where max-age=300 has expired). Enable Conditional Requests to return 304 instead of re-downloading the resource if unmodified.

[2]: Although base64 encoded images are generally much larger than PNGs, some of these images aren't used until a user clicks the "I'm not a Robot" checkbox, converting those to PNGs saves bytes but will likely have a negative effect on image rendering (hence the data URI usage?), perhaps preloading can help here, in browsers that support it. CSS animations is also an option, but that's a bigger task to take on.

If this conversion from base64 to PNG is done, the following CSS selectors (in styles__ltr.css / styles__rtl.css) can reuse the same background-image URLs to reference the then identical images, instead of having one reference the PNG version, and the other the base64 encoded version (saving 30.58 KB):

  • .recaptcha-checkbox-borderAnimation and .recaptcha-checkbox-nodatauri.recaptcha-checkbox-borderAnimation to both use the compressed PNG version of checkbox_sprite.png
  • .recaptcha-checkbox-checkmark and .recaptcha-checkbox-nodatauri.recaptcha-checkbox-checkmark to both use the compressed PNG version of checkmark_sprite.png
  • .recaptcha-checkbox-spinner and .recaptcha-checkbox-nodatauri.recaptcha-checkbox-spinner to both use the compressed PNG version of loading_sprite.png
  • .recaptcha-checkbox-spinnerAnimation and .recaptcha-checkbox-loading .recaptcha-checkbox-nodatauri.recaptcha-checkbox-spinnerAnimation to both use the compressed PNG version of loading_bg_sprite.png

That concludes a saving of roughly 240 KB in total, excluding potential savings from Brotli compression.

@rowan-m

Logo is 2.3KB PNG, would this be better as inline SVG?

The HTML resource containing that PNG isn't cacheable, inline SVG in this case would increase bandwidth usage on subsequent requests, however, compressing it reduces the size to 1.39 KB (byte savings included in the analysis above).

Malvoz avatar Dec 22 '19 20:12 Malvoz

Sounds like you should be part of the Chrome team 😃

heipei avatar Jan 31 '20 08:01 heipei

another +1 on fixing this as it is the biggest waste of resources I have atm

recaptch-redic-wtf-usage #yakillingmesmalls

ByronAP avatar Feb 11 '20 04:02 ByronAP

Another +1 here: a simple inclusion of a recaptcha on an empty HTML page results in 675 KB of resources loaded...

guillaumevp avatar Feb 24 '20 14:02 guillaumevp

+1 for this. It'd be great, if this gets fixed. It loads ~600 KB of resources for a very tiny signup form. :(

ManadayM avatar Feb 27 '20 08:02 ManadayM

+1 for this since I also have the same recaptcha__fi.js loaded 3 times.

nghitrum avatar Mar 09 '20 10:03 nghitrum

+1, got recaptcha__en.js requested 3 times: once by https://www.google.com/recaptcha/api.js once by https://www.google.com/recaptcha/api2/anchor once by webworker.js

they are the exact same files

zfeher avatar Mar 11 '20 14:03 zfeher

recaptcha__en.js requested 3 times

"requested" is the key word here.

Note that the resources are only downloaded multiple times when the HTTP cache is disabled. In actuality, the resources are requested multiple times, but only downloaded once, for subsequent requests the files are served from the cache.

This means that

~600 KB of resources

isn't true for real world users.

Malvoz avatar Mar 11 '20 15:03 Malvoz

Oh you are right I forgot about that I use Disable cache all the time for development.

Nevertheless I've still got 2 downloads of recaptcha_en.js when I start with an empty cache (after this all reloads fully works from cache ofc).

once by https://www.google.com/recaptcha/api.js once by https://www.google.com/recaptcha/api2/anchor webworker.js uses the cached one

So we might still get a double size we don't have the cached version already.

zfeher avatar Mar 11 '20 15:03 zfeher

It's absurd that this still hasn't been resolved. I mean, this isn't some random lib with 3 stars on GitHub, it's a popular lib by Google.

fabis94 avatar May 19 '20 07:05 fabis94

Would be good to get this fixed as we are still seeing recaptcha_en.js being loaded twice. When we generate a lighthouse report for our site it advises us to reduce the impact of third-party code and the top three offenders are Google CDN, Google Analytics and Google Recaptcha 😂

dansykes80 avatar Sep 18 '20 22:09 dansykes80

I don't think they care. In general GG, FB, Bing, etc. are all on the top of the offender lists including a bad cache timeout but you have no handle on that. The reports are just to show that they are doing something to HELP you. It is utter nonsense. After a recent warning I tried adding async to defer according to the most recent guidelines. No increase in the rating at all. Worse in fact.

tucoinfo avatar Sep 19 '20 00:09 tucoinfo

Google imposes how to do things, but even they don't comply. In my village, this is called politics.

milabron avatar Oct 24 '20 14:10 milabron

+1

alishahlakhani avatar Dec 01 '20 16:12 alishahlakhani

+1

rahulnuo avatar Dec 28 '20 11:12 rahulnuo

Lighthouse report... Not even served Gzipped

image

Tofandel avatar Mar 11 '21 11:03 Tofandel

any news?

ThodorisElissaios avatar Mar 20 '21 12:03 ThodorisElissaios

Guess we should switch to hCaptcha ;) image Much more reasonable with it's 24kb and tree shaking (only loads scripts it needs when it needs), api compatible with reCaptcha, no brainer for me. Still waiting for the noCaptcha implementation to be rolled out to be perfect

Tofandel avatar Mar 25 '21 07:03 Tofandel

+1 :(

luiznasciment0 avatar Apr 09 '21 14:04 luiznasciment0

+1

lexusburn avatar Apr 09 '21 16:04 lexusburn

"requested" is the key word here.

Note that the resources are only downloaded multiple times when the HTTP cache is disabled. In actuality, the resources are requested multiple times, but only downloaded once, for subsequent requests the files are served from the cache.

Because Chrome and ~most~ [2022 edit: all] modern browsers are now partitioning the cache, this is no longer true. Safari, Firefox, and now Chrome all have changed their caches in such a way that reCAPTCHA will have to download its entire bundle multiple times (as reCAPTCHA uses iframes). That compounds the issue here.

image

Leland avatar Apr 23 '21 16:04 Leland

+1

ericfurspan avatar Dec 31 '21 02:12 ericfurspan

+1

ansmlc avatar Mar 23 '22 00:03 ansmlc

+1

Anu3ev avatar Aug 04 '22 15:08 Anu3ev

+1

maximelafarie avatar Aug 24 '22 19:08 maximelafarie

Guys, you can use Intersection Observer API. Add script and initialize it when recaptcha block appears on screen. This will make it possible not to load it immediately

Anu3ev avatar Sep 27 '22 11:09 Anu3ev