Skip to content

Optimize for google pagespeed #56

@sdrenth

Description

@sdrenth

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions