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.
Hi, @LBernardo86 thanks for reaching out. I want to make sure you saw this post and this resource —optimizing your site for performance.
Hey @Indra @Anton do you have any thought on how @LBernardo86 can approach this challenge?
Thank you! — Jaycee
Hi @Jaycee_Lewis, haven’t had the chance to look at the links yet. Will check them out and see if they work.
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
2. create a custom module and modify an embed code. It should look like this
Here’s the code
{% 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
Hope this helps.
best,
Anton
@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?
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
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
hope this helps,
best,
Anton