# async javascript use in hubspot form

**URL:** <https://community.hubspot.com/t/async-javascript-use-in-hubspot-form/24038>\
**Category:** APIs & Integrations\
**Tags:** website-pages\
**Created:** [August 11, 2020, 9:29am UTC](https://community.hubspot.com/t/async-javascript-use-in-hubspot-form/24038 "2020-08-11T09:29:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashadabbas15](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ashadabbas15/32/74736_2.png) [@ashadabbas15](https://community.hubspot.com/u/ashadabbas15)\
**Post date:** [August 11, 2020, 9:29am UTC](https://community.hubspot.com/t/async-javascript-use-in-hubspot-form/24038/1 "2020-08-11T09:29:56Z")

</div>

I want the hubspot forms to use async method or can we perform lazyload on hubspot javascript file , so that we can reduce the load time  
help me ! how we can do that

files I am talking here are like forms/v2.js, leadflow.js.  
these file always load when we open a website not depending on whether user submit a hubspot form or not.

---

<div class="post-metadata">

**Author:** ![natsumimori](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/natsumimori/32/39807_2.png) [@natsumimori](https://community.hubspot.com/u/natsumimori)\
**Post date:** [August 12, 2020, 3:56am UTC](https://community.hubspot.com/t/async-javascript-use-in-hubspot-form/24038/2 "2020-08-12T03:56:19Z")

</div>

I will tag in subject matter experts here: @piersg and @stefen, are you familiar with this topic?

@ashadabbas15 Meanwhile, I wanted to share this resource: [3 Simple Steps to Create Lazy Loading Images In HubSpot](https://www.bluleadz.com/blog/lazy-loading-images-on-hubspot?utm_source=hsc-mfrankjohnson)

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [August 12, 2020, 10:29am UTC](https://community.hubspot.com/t/async-javascript-use-in-hubspot-form/24038/3 "2020-08-12T10:29:37Z")

</div>

I’m not sure this is possible sadly. Normally you would use the async or defer attribute on script tag, however, because these scripts are part of the [standard\_header\_includes](http://designers.hubspot.com/docs/hubl/hubl-supported-variables) so you obviously can’t do that.

You could add defer to the script tags as their added to the DOM using MutationObserver, but I’m not sure that’s a good idea/may slow your page down.

```auto
const observer = new MutationObserver(mutations => {
 mutations.forEach(({ addedNodes }) => {
 addedNodes.forEach(node => {
 // For each added script tag
 if(node.nodeType === 1 && node.tagName === 'SCRIPT') {
 // Adds defer attribute to the script tag in Safari, Chrome, Edge & IE
 node.setAttribute('defer', 'defer');
 }
 })
 })
})

// Starts the monitoring
observer.observe(document.documentElement, {
 childList: true,
 subtree: true
})

```

---

<div class="post-metadata">

**Author:** ![Sjardo](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/sjardo/32/52178_2.png) [@Sjardo](https://community.hubspot.com/u/Sjardo)\
**Post date:** [June 2, 2021, 7:16am UTC](https://community.hubspot.com/t/async-javascript-use-in-hubspot-form/24038/4 "2021-06-02T07:16:39Z")

</div>

Hi!

Fun thing is, if you do NOT use the standard header includes tag in your template, it’s still loaded. 😅  
Best,

---

<div class="post-metadata">

**Author:** ![stefen](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/stefen/32/29274_2.png) [@stefen](https://community.hubspot.com/u/stefen)\
**Post date:** [August 12, 2020, 2:07pm UTC](https://community.hubspot.com/t/async-javascript-use-in-hubspot-form/24038/5 "2020-08-12T14:07:02Z")

</div>

@ashadabbas15 I would post this to the ideas board, it’s something HubSpot would have to implement on their side.

---

<div class="post-metadata">

**Author:** ![SLovejoy](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@SLovejoy](https://community.hubspot.com/u/SLovejoy)\
**Post date:** [April 18, 2022, 1:28pm UTC](https://community.hubspot.com/t/async-javascript-use-in-hubspot-form/24038/6 "2022-04-18T13:28:44Z")

</div>

Any updates on this from anyone at Hubspot?

There still appears to be no way around the large .js scripts that are damaging site pagespeed performance.

---

<div class="post-metadata">

**Author:** ![Jere](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jere/32/59606_2.png) [@Jere](https://community.hubspot.com/u/Jere)\
**Post date:** [May 26, 2022, 2:40pm UTC](https://community.hubspot.com/t/async-javascript-use-in-hubspot-form/24038/7 "2022-05-26T14:40:23Z")

</div>

Still in need of this! Any update?

---

<div class="post-metadata">

**Author:** ![SLovejoy](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@SLovejoy](https://community.hubspot.com/u/SLovejoy)\
**Post date:** [May 18, 2023, 7:35am UTC](https://community.hubspot.com/t/async-javascript-use-in-hubspot-form/24038/8 "2023-05-18T07:35:42Z")

</div>

Are there any updates to this yet.
