Viewing 15 replies - 1 through 15 (of 20 total)
  • Plugin Support harthur90

    (@harthur90)

    Hi @cp1132 Thanks for your message.

    This script is responsible for loading HubSpot forms at your page. We already defer this particular script at our plugin.

    Are you using the latest version of the plugin? Also I would make sure if this script is not being manually added into any page.

    Let me know if this helps,

    Best regards

    Plugin Support harthur90

    (@harthur90)

    Closing this due to inactivity, feel free to re-open if needed.

    Best regards,

    Thread Starter cp1132

    (@cp1132)

    Version 10.1.6

    Thread Starter cp1132

    (@cp1132)

    is there a way to lazy load the hubspot script?

    Plugin Support harthur90

    (@harthur90)

    Similiar to what is done at https://plugins.svn.www.ads-software.com/leadin/trunk/public/class-pagehooks.php

    you can have your own plugin that adds async to the forms script, with the following code:

    add_filter( 'script_loader_tag', array( $this, 'add_async_to_forms_script' ), 10, 2 );
    
    public function add_async_to_forms_script( $tag, $handle ) {
    if ( 'leadin-forms-v2' === $handle ) {
    $tag = str_replace( 'src', 'async src', $tag );
    }
    return $tag;
    }

    please note that this can affect forms that are loaded inside modals.

    Thread Starter cp1132

    (@cp1132)

    Can I add that to the functions.php?

    Plugin Support harthur90

    (@harthur90)

    It would work. but I would suggest having a folder created at plugins, eg. leadin-forms-async/leadin-forms-async.php

    Thread Starter cp1132

    (@cp1132)

    does it have to be a php file? I can only add an html file with wp file manager

    https://ubigro.com/wp-content/uploads/2023/03/Screen-Shot-2023-03-29-at-3.33.45-PM.png

    How do I know if it is working?

    https://pagespeed.web.dev/analysis/https-ubigro-com/v5e0cimdl8?form_factor=desktop

    • This reply was modified 1 year, 8 months ago by cp1132.
    Plugin Support harthur90

    (@harthur90)

    A html will not work on this case. You can verify by checking if the script has the async property when inspecting the source code of the page

    best regards

    Thread Starter cp1132

    (@cp1132)

    where do i look for that here? view-source:https://ubigro.com/

    Thread Starter cp1132

    (@cp1132)

    syntax error, unexpected ‘public’ (T_PUBLIC), expecting end of file

    Thread Starter cp1132

    (@cp1132)

    I also tried this code

    <script>
    // override the hbspt functionality while hubspot is loading
    var hbspt = {
       //push form to hubcache queue
       forms:{create:function(c){hubspot.forms.push(c)}},
    };
    
    // cache hubspot forms here
    var hubcache = {
            forms:[],
            letsgo:function(){
                for (var i in hubspot.forms){
                  //hubspot is now loaded
                  hbspt.forms.create(hubcache.forms[i]);
                }            
            }
        }
    </script>


    and added defer to

    <script charset="utf-8" type="text/javascript" src="https://js.hsforms.net/forms/v2.js" defer></script>

    but nothing is helping with page speed

    https://pagespeed.web.dev/analysis/https-ubigro-com/aj5mru7dy0?form_factor=desktop

    Plugin Support harthur90

    (@harthur90)

    Our script already has the defer property and the logic to render forms after the script has been loaded – you are looking to add the async property instead

    please note the code I sent was an example, you may need to adapt to work outside of a PHP class – which is the error you got

    best regards

    • This reply was modified 1 year, 7 months ago by harthur90. Reason: add additional information
    Thread Starter cp1132

    (@cp1132)

    The file is now a php file https://ubigro.com/wp-content/uploads/2023/04/Screen-Shot-2023-04-03-at-2.07.12-PM.png

    Here is an example of my current form code on a page do I need to change anything?

    <script>
    // override the hbspt functionality while hubspot is loading
    var hbspt = {
       //push form to hubcache queue
       forms:{create:function(c){hubspot.forms.push(c)}},
    };
    
    // cache hubspot forms here
    var hubcache = {
            forms:[],
            letsgo:function(){
                for (var i in hubspot.forms){
                  //hubspot is now loaded
                  hbspt.forms.create(hubcache.forms[i]);
                }            
            }
        }
    </script>
    
    <script charset="utf-8" type="text/javascript" src="https://js.hsforms.net/forms/v2.js" defer></script>
    <script>
      hbspt.forms.create({
    	region: "na1",
    	portalId: "8419634",
    	formId: "d0de9b78-f8c6-4b96-b2fd-c2e78e483a5f"
    });
    </script>
    Plugin Support harthur90

    (@harthur90)

    You should change your php code to the following:

    function add_async_to_forms_script( $tag, $handle ) {
    if ( 'leadin-forms-v2' === $handle ) {
    $tag = str_replace( 'src', 'async src', $tag );
    }
    return $tag;
    }
    add_filter('script_loader_tag','add_async_to_forms_script')

    You can simplify you page code to the following:

    <script>					
    window.hsFormsOnReady = window.hsFormsOnReady || [];
    window.hsFormsOnReady.push(()=>{
    	hbspt.forms.create({
                    region: "na1",
    		portalId: "8419634",
                    formId: "d0de9b78-f8c6-4b96-b2fd-c2e78e483a5f",
                    target: "#your-div-id",
    		})
    });
    </script>

    • This reply was modified 1 year, 7 months ago by harthur90.
    • This reply was modified 1 year, 7 months ago by harthur90. Reason: editor
    • This reply was modified 1 year, 7 months ago by harthur90. Reason: wp editor
    • This reply was modified 1 year, 7 months ago by harthur90. Reason: add region
Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘https://js.hsforms.net/forms/embed/v2.js (js.hsforms.net)’ is closed to new replies.