How to Fix Third-Party Script Impact on Your Homepage
Every external domain your homepage loads JavaScript from adds DNS lookups, connections, main-thread work and another party that can change code on your site. This guide shows you how to list each third-party script host, remove or consolidate the ones you don't need, self-host what you can, and delay chat widgets and trackers until the visitor interacts or the browser is idle.

Why it matters
Third-party scripts are among the most common causes of poor Interaction to Next Paint (INP) and slow Largest Contentful Paint, both of which feed Google's Core Web Vitals and affect how fast pages feel on mid-range phones. Each extra host also widens your security and privacy surface: a compromised vendor script runs with full access to your page, forms and cookies, and many trackers set cookies that need consent. Fewer hosts in the initial HTML means faster rendering, more reliable crawling and rendering, and a shorter Content-Security-Policy.
What you need
Step-by-step fix
List every third-party script host in the HTML
The audit counts the distinct hostnames in <script src> tags in your homepage HTML that differ from your site's own hostname. Fetch the raw HTML (not the rendered DOM) so you see what is actually delivered. Note that subdomains count as third-party: if your site is www.example.com, scripts on cdn.example.com or example.com are counted too.
curl -sL https://www.example.com/ | grep -oiE '<script[^>]+src=["'\''][^"'\'']+' | grep -oiE 'https?://[^/"'\'']+|//[^/"'\'']+' | sed -E 's#^(https?:)?//##' | sort -u
Map each host to an owner and a purpose
Put the hosts in a spreadsheet with columns: vendor, what it does, who asked for it, last time anyone used its data, and whether it is needed on the homepage. Typical findings:
- Pixels for ad campaigns that ended months ago
- Two analytics tools collecting the same data
- Leftover code from uninstalled apps or plugins
- A/B testing or heatmap scripts with no active experiment
Remove dead and duplicate tags
Delete every script whose owner can't justify it. Check your theme header/footer templates, CMS "custom code" fields, plugin settings and your tag manager. g.
two heatmap vendors), keep one. Where a tool is only needed on checkout or a landing page, restrict it to those pages instead of loading it site-wide.
<!-- Remove blocks like these from header.php / theme.liquid / layout files --> <script src="https://static.oldheatmap.example/track.js"></script> <script src="https://connect.retiredadnetwork.example/pixel.js" async></script>
Self-host common libraries and move tags into one container
Libraries loaded from public CDNs (jQuery, Swiper, Alpine, Lodash, polyfills) can be downloaded and served from your own domain, which removes the host entirely and avoids a separate connection. For marketing pixels, move them into a single tag manager container so the HTML references one host instead of many; tags fired by the container are injected later, not in the initial HTML.
<!-- Before --> <script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script> <!-- After: file copied to your own server --> <script src="/assets/js/swiper-bundle.min.js" defer></script>
Delay chat widgets and trackers until interaction
Chat widgets, heatmaps, session recorders and review badges rarely need to run before the visitor does anything. Remove their <script src> tag and load them with a small inline loader that fires on the first scroll, tap, click or keypress, with an idle fallback. Replace the URL with your vendor's loader URL and keep any configuration variables the vendor requires above the loader.
<script>
(function () {
var done = false;
function load() {
if (done) return; done = true;
var s = document.createElement('script');
s.src = 'https://widget.chatvendor.example/loader.js';
s.async = true;
document.head.appendChild(s);
}
['pointerdown', 'keydown', 'scroll', 'touchstart'].forEach(function (e) {
window.addEventListener(e, load, { once: true, passive: true });
});
if ('requestIdleCallback' in window) {
requestIdleCallback(load, { timeout: 10000 });
} else {
setTimeout(load, 10000);
}
})();
</script>Add async or defer to the scripts you keep
For the third-party scripts that must stay in the HTML (usually consent management and your tag manager), make sure none of them block rendering. Use async for independent scripts like analytics and defer for scripts that depend on DOM order. Add preconnect only for the one or two hosts that load early and matter most.
<link rel="preconnect" href="https://www.googletagmanager.com"> <script async src="https://www.googletagmanager.com/gtm.js?id=GTM-XXXXXXX"></script>
Re-check the host count and performance
Re-run the curl command from step 1 against the live homepage after clearing any page cache or CDN cache. Aim for 6 or fewer third-party script hosts. Then run PageSpeed Insights on the homepage and compare Total Blocking Time and the "Reduce the impact of third-party code" diagnostic with your earlier result, and click through the site to confirm chat, analytics and consent still work.
curl -sL -H 'Cache-Control: no-cache' https://www.example.com/ | grep -oiE '<script[^>]+src=["'\''][^"'\'']+' | grep -oiE 'https?://[^/"'\'']+|//[^/"'\'']+' | sed -E 's#^(https?:)?//##' | sort -u | wc -l
Platform-specific notes
WordPress
Scripts come from the theme (header.php/footer.php), plugins and "insert headers and footers" style plugins. Deactivate unused plugins rather than just hiding their output. Performance plugins such as WP Rocket (File Optimization > Delay JavaScript execution), Perfmatters (Assets > Delay JavaScript) or Flying Scripts can delay named scripts until interaction without editing code.
Shopify
Most third-party scripts come from apps. Check Online Store > Themes > Customize > App embeds and switch off unused embeds, then search theme.liquid and snippets for leftover code from uninstalled apps. Pixels added via Settings > Customer events run in a sandbox rather than as script tags in your theme HTML, so moving tracking there reduces the count.
Next.js
Use the next/script component: strategy="lazyOnload" loads during browser idle time, and strategy="worker" (experimental, uses Partytown) moves scripts off the main thread. Avoid strategy="beforeInteractive" for anything except consent tooling. Self-host libraries by installing them from npm instead of linking a CDN.
Cloudflare
Cloudflare Zaraz can run many analytics and ad tools from your own domain at the edge, replacing several client-side vendor scripts with one first-party loader. Configure it under your domain's Zaraz > Tools Configuration and remove the original vendor tags afterwards.
Webflow
Check Site settings > Custom code (Head and Footer), page-level Page settings > Custom code, and Embed elements on the homepage. Webflow's own scripts load from Webflow-hosted domains and can't be removed, so focus on the custom code you added.
Check that it worked
✅ How to verify
- Run the curl command from step 1 on the live homepage and confirm 6 or fewer distinct external script hostnames.
- View the page source (Ctrl+U / Cmd+Option+U) and search for "<script src" to confirm delayed widgets no longer appear as script tags.
- In Chrome DevTools Network panel, reload without interacting and confirm the chat and heatmap requests only appear after you scroll or click.
- Run PageSpeed Insights and check that "Reduce the impact of third-party code" shows less blocking time than before.
⚠️ Common mistakes
- Hiding a widget with CSS or a plugin setting while its script tag still loads in the HTML.
- Moving scripts to a cdn.example.com subdomain and expecting them to count as first-party; only the exact page hostname does.
- Delaying the consent manager along with the trackers, which can let tags fire before consent or break the banner.
- Removing tags without checking with marketing, then losing conversion tracking for live ad campaigns.
Is this still an issue on your site? Run a free audit — ZORO checks this and 294 other SEO, AI-visibility, accessibility and security signals, with fixes for your platform.
Check my site freeFAQ
How many third-party scripts is too many?
There is no official limit, but each extra host adds connection and execution cost. Our audit passes 6 or fewer distinct third-party script hosts on the homepage and flags higher counts, with more than 12 treated as a clear problem.
Does Google Tag Manager count as one host even if it fires many tags?
In the initial HTML, yes: only googletagmanager.com appears as a script host. The tags it fires still cost performance in the browser, so keep the container lean and use triggers like Window Loaded or custom interaction events for non-essential tags.
Will delaying analytics until interaction lose data?
You will miss some visitors who leave without scrolling, tapping or pressing a key, which mostly affects bounce counts. Keep core analytics loading with async and only delay heatmaps, session recording, chat and remarketing pixels if exact bounce data matters to you.
Is it safe to self-host third-party libraries?
Yes for open-source libraries like jQuery or Swiper, and it removes a supply-chain dependency. You become responsible for updates, so note the version and check it for security releases. Don't self-host vendor tracking scripts unless the vendor supports it, as they change often.
How to Fix Web Font Loading with font-display and Preload
How to Fix Unused JavaScript and Speed Up Mobile Pages
How to Fix Mobile-Friendly Rendering and Horizontal Scroll
How to Fix Too Many HTTP Requests on Your Web Pages
How to Fix JavaScript-Dependent Content for Crawlers and AI
How to Fix Missing Lazy-Loading on Offscreen Images