Title: https://js.hsforms.net/forms/embed/v2.js (js.hsforms.net)
Last modified: March 14, 2023

---

# https://js.hsforms.net/forms/embed/v2.js (js.hsforms.net)

 *  Resolved [cp1132](https://wordpress.org/support/users/cp1132/)
 * (@cp1132)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/)
 * page speed insights is complaining about this javascript slowing down our site
   [https://js.hsforms.net/forms/embed/v2.js](https://js.hsforms.net/forms/embed/v2.js)(
   js.hsforms.net)
 * ![](https://i0.wp.com/ubigro.com/wp-content/uploads/2023/03/Screen-Shot-2023-
   03-14-at-2.53.12-PM.png?ssl=1)
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fhttps-js-hsforms-net-forms-embed-v2-js-js-hsforms-net%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/page/2/?output_format=md)

 *  [harthur90](https://wordpress.org/support/users/harthur90/)
 * (@harthur90)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16565296)
 * Hi [@cp1132](https://wordpress.org/support/users/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
 *  [harthur90](https://wordpress.org/support/users/harthur90/)
 * (@harthur90)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16583694)
 * Closing this due to inactivity, feel free to re-open if needed.
 * Best regards,
 *  Thread Starter [cp1132](https://wordpress.org/support/users/cp1132/)
 * (@cp1132)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16603156)
 * Version 10.1.6
 *  Thread Starter [cp1132](https://wordpress.org/support/users/cp1132/)
 * (@cp1132)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16603159)
 * is there a way to lazy load the hubspot script?
 *  [harthur90](https://wordpress.org/support/users/harthur90/)
 * (@harthur90)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16605743)
 * Similiar to what is done at [https://plugins.svn.wordpress.org/leadin/trunk/public/class-pagehooks.php](https://plugins.svn.wordpress.org/leadin/trunk/public/class-pagehooks.php)
 * you can have your own plugin that adds async to the forms script, with the following
   code:
 *     ```wp-block-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](https://wordpress.org/support/users/cp1132/)
 * (@cp1132)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16605945)
 * Can I add that to the functions.php?
 *  [harthur90](https://wordpress.org/support/users/harthur90/)
 * (@harthur90)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16606008)
 * It would work. but I would suggest having a folder created at plugins, eg. leadin-
   forms-async/leadin-forms-async.php
 *  Thread Starter [cp1132](https://wordpress.org/support/users/cp1132/)
 * (@cp1132)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16607535)
 * 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](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](https://pagespeed.web.dev/analysis/https-ubigro-com/v5e0cimdl8?form_factor=desktop)
    -  This reply was modified 3 years, 2 months ago by [cp1132](https://wordpress.org/support/users/cp1132/).
 *  [harthur90](https://wordpress.org/support/users/harthur90/)
 * (@harthur90)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16609184)
 * 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](https://wordpress.org/support/users/cp1132/)
 * (@cp1132)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16610687)
 * where do i look for that here? view-source:[https://ubigro.com/](https://ubigro.com/)
 *  Thread Starter [cp1132](https://wordpress.org/support/users/cp1132/)
 * (@cp1132)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16614216)
 * syntax error, unexpected ‘public’ (T_PUBLIC), expecting end of file
 *  Thread Starter [cp1132](https://wordpress.org/support/users/cp1132/)
 * (@cp1132)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16614447)
 * I also tried this code
 *     ```wp-block-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
 *     ```wp-block-code
       <script charset="utf-8" type="text/javascript" src="//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](https://pagespeed.web.dev/analysis/https-ubigro-com/aj5mru7dy0?form_factor=desktop)
 *  [harthur90](https://wordpress.org/support/users/harthur90/)
 * (@harthur90)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16620369)
 * 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 3 years, 2 months ago by [harthur90](https://wordpress.org/support/users/harthur90/).
      Reason: add additional information
 *  Thread Starter [cp1132](https://wordpress.org/support/users/cp1132/)
 * (@cp1132)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16622723)
 * 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](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?
 *     ```wp-block-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>
   
       <script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js" defer></script>
       <script>
         hbspt.forms.create({
       	region: "na1",
       	portalId: "8419634",
       	formId: "d0de9b78-f8c6-4b96-b2fd-c2e78e483a5f"
       });
       </script>
       ```
   
 *  [harthur90](https://wordpress.org/support/users/harthur90/)
 * (@harthur90)
 * [3 years, 2 months ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/#post-16624480)
 * You should change your php code to the following:
 *     ```wp-block-code
       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:
 *     ```wp-block-code
       <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 3 years, 2 months ago by [harthur90](https://wordpress.org/support/users/harthur90/).
    -  This reply was modified 3 years, 2 months ago by [harthur90](https://wordpress.org/support/users/harthur90/).
      Reason: editor
    -  This reply was modified 3 years, 2 months ago by [harthur90](https://wordpress.org/support/users/harthur90/).
      Reason: wp editor
    -  This reply was modified 3 years, 2 months ago by [harthur90](https://wordpress.org/support/users/harthur90/).
      Reason: add region

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/page/2/?output_format=md)

The topic ‘https://js.hsforms.net/forms/embed/v2.js (js.hsforms.net)’ is closed 
to new replies.

 * ![](https://ps.w.org/leadin/assets/icon-256x256.png?rev=3041936)
 * [HubSpot All-In-One Marketing - Forms, Popups, Live Chat](https://wordpress.org/plugins/leadin/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/leadin/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/leadin/)
 * [Active Topics](https://wordpress.org/support/plugin/leadin/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/leadin/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/leadin/reviews/)

 * 20 replies
 * 2 participants
 * Last reply from: [cp1132](https://wordpress.org/support/users/cp1132/)
 * Last activity: [3 years, 1 month ago](https://wordpress.org/support/topic/https-js-hsforms-net-forms-embed-v2-js-js-hsforms-net/page/2/#post-16648624)
 * Status: resolved