# Defer Scripts from Hubspot

**URL:** <https://community.hubspot.com/t/defer-scripts-from-hubspot/62892>\
**Category:** APIs & Integrations\
**Created:** [August 12, 2022, 9:57am UTC](https://community.hubspot.com/t/defer-scripts-from-hubspot/62892 "2022-08-12T09:57:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![LBernardo86](https://avatars.discourse-cdn.com/v4/letter/l/5e9695/32.png) [@LBernardo86](https://community.hubspot.com/u/LBernardo86)\
**Post date:** [August 12, 2022, 9:57am UTC](https://community.hubspot.com/t/defer-scripts-from-hubspot/62892/1 "2022-08-12T09:57:46Z")

</div>

Hi!

Is there a way to defer these scripts from Hubspot? They seem to be slowing down the LCP by a lot. These scripts are from embedded youtube videos and the comment forms.

 ![LBernardo86_0-1660298249737.png](https://d2qpr2jzcazej7.cloudfront.net/original/1X/60d570ff5e55b0fee2c5b3d669023108de1e3fc9.png)

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [August 12, 2022, 8:53pm UTC](https://community.hubspot.com/t/defer-scripts-from-hubspot/62892/2 "2022-08-12T20:53:59Z")

</div>

Hi, @LBernardo86 thanks for reaching out. I want to make sure you saw this [post](https://community.hubspot.com/t5/CMS-Development/Google-PageSpeed-Insights-LCP-optimization-for-mobile/m-p/399740#M20534) and this resource —[optimizing your site for performance](https://developers.hubspot.com/docs/cms/guides/speed).

Hey @Indra @Anton do you have any thought on how @LBernardo86 can approach this challenge?

Thank you! — Jaycee

---

<div class="post-metadata">

**Author:** ![LBernardo86](https://avatars.discourse-cdn.com/v4/letter/l/5e9695/32.png) [@LBernardo86](https://community.hubspot.com/u/LBernardo86)\
**Post date:** [August 15, 2022, 2:02am UTC](https://community.hubspot.com/t/defer-scripts-from-hubspot/62892/3 "2022-08-15T02:02:44Z")

</div>

Hi [@Jaycee\_Lewis](https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074), haven’t had the chance to look at the links yet. Will check them out and see if they work.

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [August 15, 2022, 9:02am UTC](https://community.hubspot.com/t/defer-scripts-from-hubspot/62892/4 "2022-08-15T09:02:25Z")

</div>

Hi @LBernardo86,

could you please provide a preview link?

How do you embed your scripts? in a “rich-text” or custom modules?

Defering the v2.js(form script) is - as far as I know - only possible with a custom solution and even then it is not guaranteed to work.

There are many ways how to create custom modules. Here are two

**1. create a custom module with just form function - no real benefit in terms of performance**

 ![Anton_0-1660552248200.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/5/56c837cc7cd91f0e9f4fada86988edf2413b6db9.png)

**2. create a custom module and modify an embed code. It should look like this**

 ![Anton_1-1660552671617.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/f/6/f67b54e04fb25040dd2d812eab250a7f6f9a1241.png)

Here’s the code

```lia-code-sample
{% require_head, defer=True %} {# will put the script to head-tag. Must be loaded before the second script! #}
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
{% end_require_head %}

<script>
 hbspt.forms.create({
 region: "na1",
 portalId: "{{ hub_id }}", 
 formId: "{{ module.form_select.form_id }}"
 });
</script>

```

The best part about this is - you can almost completly modify the embed code to your needs with [this documentation](https://legacydocs.hubspot.com/docs/methods/forms/advanced_form_options)

Hope this helps.

best,

Anton

---

<div class="post-metadata">

**Author:** ![LBernardo86](https://avatars.discourse-cdn.com/v4/letter/l/5e9695/32.png) [@LBernardo86](https://community.hubspot.com/u/LBernardo86)\
**Post date:** [August 18, 2022, 6:10am UTC](https://community.hubspot.com/t/defer-scripts-from-hubspot/62892/5 "2022-08-18T06:10:47Z")

</div>

@Anton I am using the drag and drop modules from hubspot. I did find a way to manually call the comment section. The only thing I am missing is the reply to comment functionality. I cannot find any posts here regarding that. could you point me to where I can find it?

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [August 18, 2022, 6:40am UTC](https://community.hubspot.com/t/defer-scripts-from-hubspot/62892/6 "2022-08-18T06:40:11Z")

</div>

Hi @LBernardo86,

great!

Do I get it right that you’d like to have the comment function outside on a LCP/outside the blog?

If so you’ll need to build/integrate something by yourself since HubSpot doesn’t support comments outside of the blog by default.

A few easier 3rd party tools for this approach would be

- [Viafoura](https://viafoura.com/audience-engagement/#engage)
- [Disqus](https://disqus.com)

Haven’t really worked with them but it should be as easy as “copy/paste” some lines of code somewhere in HubSpot.

If you’re talking about a blog - comments working only in post templates. This is the only (default) module you need

`{% module "blog_comments" path="@hubspot/blog_comments" %}`

everything else (comment form …) should be loaded automatically.

Here’s a screen of comment settings from a brand new blog and only changed the depth to 3

 ![Anton_0-1660804753315.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/c/1/c1604c4d184ab9bc4cb8ee927413308779a41d80.png)

hope this helps,

best,

Anton

---

<div class="post-metadata">

**Author:** ![LBernardo86](https://avatars.discourse-cdn.com/v4/letter/l/5e9695/32.png) [@LBernardo86](https://community.hubspot.com/u/LBernardo86)\
**Post date:** [August 22, 2022, 8:56am UTC](https://community.hubspot.com/t/defer-scripts-from-hubspot/62892/7 "2022-08-22T08:56:40Z")

</div>

Hi all, I was able to find a workaround regarding the forms in HubSpot. The next thing I wanted to see was where these facebook scripts are coming from? I couldn’t find them anywhere where I put my scripts so I was wondering maybe they are injected from somewhere else?

 ![LBernardo86_0-1661158589526.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/a/9/a9dd20c057b2e482b8eb789f509ddf153816e2e1.png)
