Oleg Kuibar
Back to Blog
Frontend 4 min read

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.

By Oleg Kuibar |

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:

CategoryScriptsTypical Blocking Time
AnalyticsSegment, GA4, Amplitude, Mixpanel, Heap150-220ms each
MarketingGTM, Facebook Pixel, LinkedIn, Twitter, TikTok90-280ms each
ComplianceOneTrust, TrustArc180-340ms each
SupportIntercom, Zendesk280-420ms each
MonitoringSentry, Datadog RUM120-160ms each
Fraud PreventionSift, FullStory240-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

  1. Script calls DOM - Hits a JS Proxy instead of the real DOM
  2. Sync XHR intercept - Service Worker catches and relays to main thread
  3. 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:

MetricBeforeAfterImprovement
Time to Interactive4.2s1.8s-57%
Total Blocking Time890ms120ms-87%
Interaction to Next Paint280ms65ms-77%
App CPU Share35%94%+169%
Frame Rate24fps60fpsSmooth

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

  1. Install Partytown in your project
  2. Add the Partytown script loader to your page
  3. Change type="text/javascript" to type="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.