Partytown: Offload Third-Party Scripts to a Web Worker
Move analytics, compliance, and tracking scripts off the main thread. Your app runs unblocked while third-party code executes in a Web Worker.
Offload Third-Party Scripts to a Web Worker
Move analytics, compliance, and tracking off the main thread. Your app runs unblocked.
The Problem
A typical fintech loads 18+ third-party scripts. Each one blocks your main thread.
Here’s a breakdown of what those scripts look like in a real application:
| Category | Scripts | Typical Blocking Time |
|---|---|---|
| Analytics | Segment, GA4, Amplitude, Mixpanel, Heap | 150-220ms each |
| Marketing | GTM, Facebook Pixel, LinkedIn, Twitter, TikTok | 90-280ms each |
| Compliance | OneTrust, TrustArc | 180-340ms each |
| Support | Intercom, Zendesk | 280-420ms each |
| Monitoring | Sentry, Datadog RUM | 120-160ms each |
| Fraud Prevention | Sift, FullStory | 240-380ms each |
Total main thread blocking: ~3,760ms
This directly impacts your Core Web Vitals:
- Time to Interactive (TTI): +2.4s
- Total Blocking Time (TBT): 890ms
- Interaction to Next Paint (INP): 280ms
The Impact
Your app competes for CPU time with scripts you don’t control. Without optimization:
- Frame rate drops from 60fps to 24fps during script initialization
- Your app only gets ~35% of available CPU time
- User interactions feel sluggish and unresponsive
The Solution: Move Scripts to a Web Worker
Partytown proxies DOM access so scripts work unchanged while running in a separate thread.
How It Works
- Script calls DOM - Hits a JS Proxy instead of the real DOM
- Sync XHR intercept - Service Worker catches and relays to main thread
- Response returns - Script continues as if DOM was local
The Flow
Implementation
The implementation is remarkably simple. No script modifications. No vendor coordination.
<!-- Add type="text/partytown" to any script -->
<script type="text/partytown"
src="https://www.googletagmanager.com/gtm.js"></script>
<script type="text/partytown"
src="https://js.sentry-cdn.com/xxx.min.js"></script>
<script type="text/partytown"
src="https://cdn.segment.com/analytics.js"></script>
That’s it. One attribute change per script.
Results
With Partytown enabled:
| Metric | Before | After | Improvement |
|---|---|---|---|
| Time to Interactive | 4.2s | 1.8s | -57% |
| Total Blocking Time | 890ms | 120ms | -87% |
| Interaction to Next Paint | 280ms | 65ms | -77% |
| App CPU Share | 35% | 94% | +169% |
| Frame Rate | 24fps | 60fps | Smooth |
Verified Compatible Services
Partytown has been tested and verified compatible with:
- Analytics: Segment, Amplitude, Mixpanel, Heap, Google Analytics
- Tag Management: Google Tag Manager
- Error Tracking: Sentry, Datadog RUM
- Feature Flags: LaunchDarkly
- Support: Intercom
- Compliance: OneTrust
- Marketing: Facebook Pixel, LinkedIn Insight, Hotjar, FullStory
- Payments: Stripe.js
Getting Started
- Install Partytown in your project
- Add the Partytown script loader to your page
- Change
type="text/javascript"totype="text/partytown"on third-party scripts
For detailed setup instructions, visit the official documentation.
Conclusion
Third-party scripts are necessary for modern web applications, but they shouldn’t come at the cost of user experience. Partytown provides a elegant solution: keep all your analytics, tracking, and compliance scripts while giving your main thread back to your application.
The result? Dramatically improved Core Web Vitals, smoother interactions, and happier users.