What if Google Analytics, Facebook Pixel, and every other third-party script ran in a web worker — freeing your main thread completely?
Partytown by Builder.io moves third-party scripts off the main thread into a web worker.
The Problem
Third-party scripts are the biggest performance killer on most websites. Google Analytics alone adds 30-50ms of main thread blocking. Add Facebook Pixel, HubSpot, Intercom, and hotjar — you lose 200-400ms of interactivity.
Partytown intercepts these scripts and runs them in a web worker. Your main thread stays free for your application code.
How It Works
<!-- Before: blocks main thread -->
<script src="https://www.googletagmanager.com/gtag/js?id=GA_ID"></script>
<!-- After: runs in web worker -->
<script type="text/partytown" src="https://www.googletagmanager.com/gtag/js?id=GA_ID"></script>
That's the entire change. Add type="text/partytown" to any script tag.
Framework Integration
npm install @builder.io/partytown
Next.js:
import { Partytown } from "@builder.io/partytown/react";
export default function Document() {
return (
<html>
<head>
<Partytown debug={true} forward={["dataLayer.push"]} />
<script type="text/partytown" src="https://www.googletagmanager.com/gtag/js" />
</head>
<body>{/* ... */}</body>
</html>
);
}
Astro:
---
import { Partytown } from "@builder.io/partytown/astro";
---
<head>
<Partytown />
</head>
Real Use Case
An e-commerce site had a Lighthouse performance score of 62 — dragged down by 8 third-party scripts. After adding Partytown, the score jumped to 91. No script was removed, no functionality lost. Main thread blocking time dropped from 340ms to 45ms.
When to Use Partytown
- Sites with 3+ third-party analytics/marketing scripts
- E-commerce sites where Core Web Vitals affect SEO
- Landing pages where every millisecond of load time affects conversion
- Any site where you cannot remove third-party scripts but need performance
Get Started
Visit partytown.builder.io — open source, works with any framework.
Need custom data pipelines or scraping solutions? Check out my Apify actors or email me at spinov001@gmail.com for custom solutions.
Top comments (0)