How to defer JavaScript to improve page speed and SEO

How to defer JavaScript to improve page speed and SEO

JavaScript is the most common performance bottleneck on the modern web. Not because JavaScript is inherently slow, but because of how and when it loads. In 2026, with Interaction to Next Paint now a Core Web Vital and Google’s field data measurement more precise than ever, the way your scripts load is directly connected to how your site ranks. Deferring JavaScript is one of the highest-impact technical fixes available — and one of the most consistently misunderstood.


Why JavaScript blocks page rendering

When a browser encounters a script tag in the HTML, it stops everything. It downloads the script, executes it, and only then continues building the page. This is called render-blocking behaviour, and it means users stare at a blank or partial page while scripts that may have nothing to do with the initial view finish loading.

On a site with multiple scripts — analytics, chat widgets, marketing pixels, font loaders — this blocking behaviour stacks. Each script adds to the delay before the page becomes visible and usable. Largest Contentful Paint suffers because the main content can’t render until the blocking scripts finish. Interaction to Next Paint suffers because the main thread is occupied with script execution instead of responding to user input.


The difference between defer and async

Two attributes exist specifically to stop scripts from blocking rendering. They are similar but not interchangeable.

The defer attribute

Adding defer to a script tag tells the browser to download the script in the background while the HTML continues parsing, then execute it only after the full document has been parsed. Deferred scripts execute in order, which matters when one script depends on another. This is the right choice for most scripts that need the DOM to be ready before they run.

The async attribute

Adding async tells the browser to download the script in the background and execute it as soon as it finishes downloading, regardless of where the browser is in parsing the HTML. Async scripts execute out of order and can interrupt rendering if they finish downloading early. This makes async appropriate for fully independent scripts — analytics tags, for example — where execution order doesn’t matter and the script has no dependencies.


What should and should not be deferred

Not every script is a candidate for deferral. Scripts that are critical to the initial render — anything that controls layout, above-the-fold styling, or core functionality the user sees immediately — should load normally. Deferring them creates a different problem: a flash of unstyled content or a broken initial view.

Scripts that are safe to defer include analytics and tracking tags, social sharing buttons, chat and support widgets, marketing pixels, and any functionality that lives below the fold or triggers on user interaction. In practice, this covers the majority of third-party scripts running on most sites.


Where most implementations go wrong

The most common mistake is applying defer or async indiscriminately to every script without understanding dependencies. A script deferred when another script it depends on loads normally will execute before its dependency is ready, causing errors that break functionality silently. The fix is auditing dependencies before changing load behaviour, not after.

The second common mistake is deferring scripts through a tag manager without auditing what the tag manager itself is doing. A deferred tag manager that fires six synchronous tags has only partially solved the problem. Each tag inside the manager needs the same scrutiny as scripts loaded directly.

Third-party script management platforms have matured significantly in 2026 and offer granular control over when and how external scripts load. For sites with complex script stacks, these tools are worth the investment before attempting manual deferral across dozens of tags.


The measurable impact

Correctly implemented script deferral consistently produces improvements in Largest Contentful Paint and Interaction to Next Paint — the two Core Web Vitals with the most direct ranking implications. The gains are not marginal. Sites moving from render-blocking scripts to properly deferred loading routinely see LCP improvements of one to two seconds and INP improvements that shift them from failing to passing thresholds.

Run a full JavaScript audit on your site with SEO Sets to identify which scripts are render-blocking, which are safe to defer, and where your script stack is creating the most damage to your page experience scores.


Frequently asked questions

Does deferring JavaScript always improve page speed?

It improves render performance when applied correctly to non-critical scripts. Applied incorrectly to scripts the page depends on for initial rendering, it can create visual errors that hurt both user experience and performance scores.

Can I defer scripts added by my CMS or page builder without breaking the site?

Sometimes. CMS-injected scripts often have dependencies that make deferral risky without testing. Always test in a staging environment before applying changes to a live site.

Is async or defer better for Google Analytics?

Async is the standard recommendation for analytics scripts since they are fully independent and execution order does not matter. Most analytics providers load their tags asynchronously by default in their current implementations.

How do I identify which scripts on my site are render-blocking?

Run a PageSpeed Insights report or a Lighthouse audit. Both surface render-blocking resources explicitly and estimate the time savings available from eliminating them.

Does deferring JavaScript affect how Google crawls and indexes the page?

Googlebot renders JavaScript, so deferred scripts will still be executed during crawling. However, pages that render faster are crawled more efficiently, and improved Core Web Vitals field scores from deferral do positively influence rankings.