Skip to content
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

Optimize for google pagespeed #56

Open
sdrenth opened this issue Jun 23, 2021 · 1 comment
Open

Optimize for google pagespeed #56

sdrenth opened this issue Jun 23, 2021 · 1 comment

Comments

@sdrenth
Copy link

sdrenth commented Jun 23, 2021

Loading the recaptcha library impacts the google pagespeed. This can be resolved by loading it deferred like this:

<script src="https://www.google.com/recaptcha/api.js?render=[[+site_key]]&hl=[[++cultureKey]]&onload=onloadCallback&render=explicit" defer></script>
<input type="hidden" name="[[+token_key]]">
<input type="hidden" name="[[+action_key]]" value="[[+form_id]]">

<script>
    function onloadCallback() {
        grecaptcha.ready(function() {
            grecaptcha.execute('[[+site_key]]', {action: '[[+form_id]]'}).then(function(token) {
                document.querySelector('[name="[[+token_key]]"]').value = token;
            });
        });
    }
</script>

Note the defer attribute on the script element and the onloadCallback function.

I think it would not be a problem to load it deferred in the default chunk.

@sepiariver
Copy link
Owner

Hello @sdrenth thanks for the feedback and definitely will add some documentation for this, perhaps here?

https://sepiariver.com/modx/a-guide-to-recaptcha-v3-for-modx-cms/

The default chunk is meant as that: a default starting point that can be customized for any implementation. The challenge with changing it is that some sites, which have already implemented the default, may break on update if there’s an expectation that the script will be called as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants