
Partytown Has Free Web Worker Magic — Here's How to Move Third-Party Scripts Off the Main Thread
Google Analytics, Facebook Pixel, chat widgets — they all block your main thread. Partytown moves them to a web worker so your site stays fast. The Problem Third-party scripts (analytics, ads, chat) can add 500ms-2s to your page load. They compete with your app for the main thread. The Solution Partytown runs third-party scripts in a web worker. Your main thread stays free for your app. Before: Main Thread = Your App + Analytics + Ads + Chat (competing) After: Main Thread = Your App only (fast) Web Worker = Analytics + Ads + Chat (isolated) Quick Start bun add @builder.io/partytown Vanilla HTML <script> partytown = { forward : [ ' dataLayer.push ' ] }; </script> <script src= "/~partytown/partytown.js" ></script> <!-- Add type="text/partytown" to move scripts to worker --> <script type= "text/partytown" src= "https://www.googletagmanager.com/gtag/js?id=G-XXXXX" ></script> <script type= "text/partytown" > window . dataLayer = window . dataLayer || []; function gtag (){ dataLayer . push (
Continue reading on Dev.to JavaScript
Opens in a new tab



