Third-party scripts are JavaScript files loaded from domains other than your own. They include analytics, advertising, social media widgets, chat tools, and more.
Common third-party scripts
- Google Analytics / Tag Manager
- Facebook Pixel
- Chat widgets (Intercom, Drift)
- Advertising scripts
- Social sharing buttons
- Video embeds
- A/B testing tools
Performance impact
Third-party scripts can significantly affect:
- Load time: Additional network requests
- Main thread: Competing for execution time
- TBT: Blocking user interactions
- CLS: Injecting content
Measuring third-party impact
Tools to identify slow scripts:
- Lighthouse "Third-party usage" audit
- Chrome DevTools Network panel
- WebPageTest third-party breakdown
Optimizing third-party scripts
Load asynchronously
<script src="analytics.js" async></script>
Delay until needed
// Load chat only when user scrolls
window.addEventListener('scroll', loadChat, { once: true });
Use facades
Show static placeholder, load real widget on interaction.
Self-host when possible
Host fonts and libraries locally for better control.
Related Terms
JavaScript Execution Time
The time the browser spends parsing, compiling, and executing JavaScript code, which can block the main thread and delay interactivity.
Main Thread
The primary thread in a browser where JavaScript execution, DOM manipulation, and rendering operations occur.
Render Blocking
Resources that prevent the browser from rendering page content until they are fully downloaded and processed.
Total Blocking Time (TBT)
A lab metric that measures the total amount of time the main thread was blocked long enough to prevent input responsiveness.