Third-Party Script Performance Budget
Track and manage third-party script performance impact. Set budgets for analytics, advertising, social widgets, A/B testing, and chat tools with strategies for lazy loading and facade patterns.
Detailed Explanation
Third-Party Script Budgets
Third-party scripts are the single biggest threat to performance budgets. Studies show that third-party code accounts for 55-70% of JavaScript on the median web page. Without explicit budgets, third-party scripts silently erode site performance.
Common Third-Party Script Sizes
| Category | Typical Size (gzipped) |
|---|---|
| Google Analytics | 20 KB |
| Google Tag Manager | 30-80 KB (depends on tags) |
| Facebook Pixel | 60 KB |
| Intercom Chat | 200-400 KB |
| Hotjar | 40-80 KB |
| Stripe.js | 30-50 KB |
| reCAPTCHA | 150-200 KB |
Setting a Third-Party Budget
A practical approach is to allocate a percentage of your total JS budget:
| Strictness | Third-Party Budget |
|---|---|
| Strict | 20% of JS budget |
| Moderate | 30% of JS budget |
| Lenient | 40% of JS budget |
For a 200 KB JS budget with moderate strictness: 200 x 0.3 = 60 KB for third-party scripts.
Mitigation Strategies
- Lazy loading — Load analytics and chat widgets after user interaction
- Facade pattern — Show a static placeholder until the user clicks (e.g., YouTube facade)
- Self-hosting — Host third-party scripts on your CDN for better caching and connection reuse
- Tag manager governance — Require performance review before adding new tags
- requestIdleCallback — Initialize non-critical scripts during idle time
Tracking in the Budget Tracker
Add each third-party script as a separate resource entry with type "JavaScript":
google-analytics.js— 20 KBintercom-widget.js— 300 KBstripe-checkout.js— 40 KB
This makes the cumulative cost visible and enables informed decisions about which scripts to keep, optimize, or remove.
The "Tag Tax" Audit
Quarterly, export your budget and compare against the previous quarter. Third-party scripts tend to grow over time as marketing and product teams add new tools. A regular audit ensures no single category silently exceeds its allocation.
Use Case
Third-party budget tracking is essential for marketing-heavy sites where multiple teams add scripts independently. A typical e-commerce site may have 15-20 third-party scripts added by marketing, product, and engineering teams. Without tracking, these scripts collectively push the page to 2-3 MB of JavaScript.