What is the impact of third-party scripts on performance?

Answer

Third-party scripts (analytics, ads, chat, social widgets, A/B testing) are one of the most common causes of poor Core Web Vitals in the real world. Their impact: LCP: scripts that execute before the LCP image is discovered delay loading. INP: third-party scripts add event listeners and run code on the main thread — long tasks delay interaction responses. CLS: ad scripts inject content dynamically, causing layout shifts. TBT: long-running third-party scripts block the main thread. Measurement: Chrome DevTools Network panel → filter by third-party domains. Mitigation strategies: Defer loading: use async or defer third-party scripts. Load after DOMContentLoaded. Partytown: run third-party scripts in a Web Worker, off the main thread. Facade pattern: show a placeholder (e.g., a static thumbnail for YouTube embeds) instead of loading the full embed until user interacts. Self-host: host analytics (Plausible, Umami) yourself to avoid third-party connections. Audit regularly: remove unused scripts. Google Tag Manager scripts especially accumulate hidden performance debt.