Third-Party Scripts Are Your Slowest Code: Auditing Tags, Widgets and Embeds
Analytics, chat widgets, ad tags and embeds often outweigh your own JavaScript. A practical audit process, loading strategies that keep pages responsive, and how to say no to the next tag request.

A client's marketing site scored poorly on interaction responsiveness, and the team spent a week optimising their own JavaScript bundle. It was 90 KB. The third-party scripts on the same page — two analytics tools, a chat widget, a heatmap recorder, a video embed and a social feed — added up to more than 1.4 MB and most of the main-thread time.
Your slowest code is usually code you did not write.
Inventory everything
Open the network panel, filter by third-party domains, and list every script with:
- What it does and who asked for it
- Its transferred size and main-thread time
- Whether it loads on every page or only where needed
- Whether anyone still uses its data
Script Size Main thread Owner Still used?
chat-widget.js 410 KB 620 ms Support Yes, pricing page only
heatmap.js 180 KB 340 ms Marketing No — trial ended
social-feed.js 290 KB 410 ms Unknown NoIn nearly every audit, a quarter or more of the scripts belong to tools nobody uses any more.
Remove first
The fastest script is the one you delete. Abandoned trials, duplicate analytics, and widgets added for a campaign two years ago go first. This step alone often produces the biggest improvement.
Load the rest deliberately
| Strategy | Use for | |---|---| | defer / async | Scripts that do not need to block rendering — nearly all of them | | Load after interaction | Chat widgets, video players, maps | | Load on specific pages | Tools that only matter in one flow | | Facades | Show a static preview; load the real embed on click |
A facade is especially effective for video embeds and chat widgets. Show a lightweight placeholder that looks like the real thing and load the heavy script only when the user clicks.
button.addEventListener(class="text-code-string">"click", async () => {
await loadScript(class="text-code-string">"https://widget.example.com/chat.js");
window.ChatWidget.open();
}, { once: true });Watch for layout shift
Ads and embeds that inject content without reserved space cause layout shift. Reserve the slot size in CSS with min-height or aspect-ratio before the script fills it. For ad slots with variable sizes, reserve the most common size.
Ads deserve special care
Ad revenue matters for a content site, and ad scripts are often the heaviest on the page. Balance it:
- Load ad scripts asynchronously, never blocking content
- Reserve every slot's space to prevent shifts
- Lazy-load slots below the fold
- Limit the number of ad units per page — more units rarely means proportionally more revenue
Put governance in place
New tags should go through the same review as new code: what it does, what it costs in performance, who owns it, and when it will be reviewed. A tag manager makes adding scripts easy, which is exactly why it needs rules.
Monitor continuously
Track page weight and responsiveness metrics in real-user monitoring, and alert when third-party weight grows. Tags creep back in through marketing tools, A/B tests and vendor updates. Re-run the audit every quarter.
The result
After that client's audit we removed four scripts, put the chat widget behind a facade, and moved the video embed to load on click. Main-thread blocking time dropped by about 70%, and interaction responsiveness moved comfortably into the good range — without touching their own 90 KB bundle.
Before optimising your own code, look at everyone else's on the page.
Paj Digital Labs
The engineering journal of Paj Digital Solutions — hosting, server infrastructure and web engineering, written by the people who run the servers.
Related reading

International Websites: Locale URLs, Hreflang and Formatting Without Guesswork
Language, country and formatting are related but different choices. Give translated pages stable URLs, preserve user selection and keep search signals aligned with real equivalents.

Progressive Enhancement for Article Sites: The Page Should Outlive Its Scripts
Core reading and navigation should remain available when hydration or a third-party script fails. Start with useful HTML and layer interactions without turning every link into an application dependency.

Website Search That Finds Answers: Ranking, Typos and Empty Results
Search quality depends on the documents and ranking rules, not the size of the input box. Index useful fields, handle imperfect queries and give readers a way forward when nothing matches.