
Partytown Has a Free Web Worker Library for Third-Party Scripts — Here's How to Use It
Google Analytics, Facebook Pixel, and chat widgets block your main thread. Partytown moves them to a web worker — your site stays fast while third-party scripts run in the background. What Is Partytown? Partytown is a library that moves resource-heavy third-party scripts off the main thread into a web worker. Your site's interactivity isn't blocked by analytics, ads, or tracking scripts. The Problem Third-party scripts typically: Block the main thread for 200-500ms each Delay Time to Interactive (TTI) by 2-5 seconds Cause layout shifts and jank Account for 50-70% of JavaScript execution time Quick Start npm install @builder.io/partytown Next.js // pages/_document.tsx import { Html , Head , Main , NextScript } from ' next/document ' ; export default function Document () { return ( < Html > < Head > < script type = "text/partytown" dangerouslySetInnerHTML = { { __html : ` window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('
Continue reading on Dev.to JavaScript
Opens in a new tab

