The hidden cost of third-party scripts
6 min readPerformance
Third-party scripts cost far more than their file size implies, because they execute on the main thread while the browser is trying to become interactive. A single consent banner loaded before hydration can cost ten or more Lighthouse points, almost all of it Total Blocking Time.
What does one script actually cost?
Here is a real case. A site scoring 99 added a cookie consent banner and dropped to 88. Nothing else changed. No new images, no new content, no code changes beyond four lines adding the script.
The eleven points came almost entirely from Total Blocking Time, which carries 30% of the Lighthouse weighting — more than any other metric. The script had been set to load before hydration, which meant it ran on the main thread during precisely the window being measured.
Why does load order matter so much?
Because the main thread is single-threaded and the browser cannot respond to the user while it is executing your script. Loading something before hydration blocks the most sensitive moment in the page lifecycle.
Moving the same script to load after hydration recovered most of the lost points. The file was identical. The only change was when it ran.
The one case where blocking early is correct: a consent manager that must gate other tracking scripts. If it loads late, the trackers it is supposed to block have already fired. If you have no other trackers, that reason does not apply and you are paying for nothing.
How do I audit what my site is loading?
Open DevTools, go to the Network tab, filter to JS and sort by domain. Every domain that is not yours is a third party. Most sites are surprised by the list.
For each one, ask three questions: does anyone still use the data it produces, does it need to run before the page is interactive, and would anything break if it were removed. In my experience roughly a third of tags on an established site fail all three.
How do I reduce the cost without removing them?
Load later
Almost nothing needs to run before hydration. Analytics, chat widgets and heat maps can all wait until the page is interactive.
Use dns-prefetch rather than preconnect
Preconnect opens a full TLS connection immediately, which competes with your own critical resources. For a non-urgent third party, resolving DNS early is enough.
Self-host what you can
Fonts are the obvious case. Self-hosting removes an origin, a connection and a privacy problem in one change.
Measure before and after
Add one tag at a time and re-run PageSpeed. Adding five at once and discovering the score dropped tells you nothing about which one to remove.
Common questions
- Do cookie banners slow down websites?
- Yes, measurably. A consent banner is a third-party script that typically renders above the fold. Expect several Lighthouse points, mostly in Total Blocking Time, and watch for layout shift when the banner appears.
- Is Google Tag Manager bad for performance?
- Tag Manager itself is small. The problem is that it makes adding tags easy, so sites accumulate them. The container is rarely the cost; what people put inside it usually is.
- Should I remove analytics to improve my score?
- Only if nobody uses it. Improving a lab score by removing data you genuinely rely on is a bad trade. Load it later instead — that usually recovers most of the cost.