Deferring HubSpot

By admin , 7 March, 2026
Deferring HubSpot by @yassinetk.codes

When a browser loads a web page, it reads HTML from top to bottom and builds the DOM. The moment it encounters a <script> tag, it stops everything — downloads the script, executes it, then resumes parsing. This is called a parser-blocking script.

HubSpot forms

The default HubSpot Forms embed looks like this:

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

Because there is no defer attribute, the browser halts HTML parsing every time it hits this line. On a slow network or a cold CDN connection, this single script can delay the page by 200–400 milliseconds before the browser has even started rendering any visible content. That delay directly hurts your Largest Contentful Paint (LCP) score.

defer Attribute

The solution is a one-word change:

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

The defer attribute tells the browser two things. First, fetch this script in the background while HTML parsing continues normally. Second, only execute it after the full HTML document has been parsed.

The script still runs on every page load and HubSpot still collects all its data — it simply no longer holds the parser hostage while doing so.

Impact on Largest Contentful Paint (LCP)

LCP measures the time from when a user first navigates to a page to when the largest visible element in the viewport — typically a hero image or a main heading — has fully rendered. Any resource that blocks the HTML parser directly delays that moment.

By deferring HubSpot's script, the browser can immediately continue parsing, discover the hero image or heading earlier, and begin fetching and rendering it without waiting for a synchronous network round-trip to HubSpot's CDN. Depending on network conditions and file size, this change alone can reduce LCP by 200–500 milliseconds on real-user connections.

Summary

Adding defer to the HubSpot Forms script tag is a minimal, low-risk change with a meaningful performance payoff. It unblocks the HTML parser, allows the browser to reach and render the page's primary content sooner, and directly improves LCP without affecting any HubSpot functionality.

Comments