Skip to content

Magento 2.4 Recaptcha load js only on popup open

After I created a module following this tutorial
Magento 2.4 Add Recaptcha in Custom From
I put my module in a popup and I would like to avoid to load all unnecessary js until I open my popup. I know that this issue comes because I modify the frontend layout

<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">

  <body>
    <referenceContainer name="content">
          <block class="MagentoFrameworkViewElementTemplate"
                 name="demo.for.recaptcha"
                 template="VendoreName_DemoRecaptcha::form.phtml"
                 >
                <container name="form.additional.info.demo.for.recaptcha">
                  <block class="MagentoReCaptchaUiBlockReCaptcha"
                         name="recaptcha"
                         after="-"
                         template="Magento_ReCaptchaFrontendUi::recaptcha.phtml"
                         ifconfig="recaptcha_frontend/type_for/customform">
                      <arguments>
                          <argument name="recaptcha_for" xsi:type="string">customform</argument>
                          <argument name="jsLayout" xsi:type="array">
                              <item name="components" xsi:type="array">
                                  <item name="recaptcha" xsi:type="array">
                                      <item name="component" xsi:type="string">Magento_ReCaptchaFrontendUi/js/reCaptcha</item>
                                  </item>
                              </item>
                          </argument>
                      </arguments>
                  </block>
                </container>
          </block>
    </referenceContainer>
  </body>
</page>

Is the any method to trigger item when I open my popup?

                                      <item name="component" xsi:type="string">Magento_ReCaptchaFrontendUi/js/reCaptcha</item>

thanks