CodePark/ questions / Third-party scripts
START PRACTICINGPRACTICE
Frontend question · Browser & web performance › Third-party scripts

How do third-party scripts like analytics, ads, chat widgets and A/B testing tools hurt performance, and how do you keep them under control?

Third-party scripts run on your main thread with the same power as your own code, but you don't control their size or behaviour.

How they hurt:

  • They add JavaScript to download, parse and run, which causes long tasks and bad INP.
  • Each new domain needs its own DNS lookup, connection and TLS handshake.
  • Synchronous scripts in the <head> block rendering. A/B testing tools often hide the page until they run.
  • Embeds and ads can inject content late and cause layout shift.
  • They often load more scripts themselves, and they can be slow or down.

How to control them:

  • Audit: list every tag. Remove the ones nobody uses. Measure each one by blocking its URL in DevTools and comparing.
  • Load them later: use async or defer, or load them after the page is interactive.
  • Use a facade: show a light placeholder, and load the real widget only when the user clicks it.
  • Connect early to the ones you must load fast, with preconnect.
  • Self-host small, stable scripts so they share your connection and caching.
  • Reserve space for ads and embeds with a fixed size, so they don't shift the layout.
  • Own the process: a performance budget, and a review before marketing adds a tag to the tag manager.
  • Third-party scripts run on the main thread and cause long tasks.
  • Each new domain costs an extra connection.
  • Remove unused tags, and measure each one by blocking it in DevTools.
  • Load scripts with async or defer, or after the page is interactive.
  • Use facades to load heavy widgets only when the user needs them.
  • Reserve space for embeds and ads to avoid layout shift.