Why defer-and-load beats worker sandboxing for most third-party scripts
Partytown is a clever idea that breaks every DOM-touching script. Here is why a simpler defer model wins for the majority of stacks — and the niche where sandboxing still has value.
Partytown's pitch is irresistible: take all your third-party scripts, run them in a Web Worker, and your main thread stays free forever. In practice, the architecture fights you the moment a script touches the DOM.
What sandboxing breaks
Web Workers don't have access to the DOM. To make third-party scripts run in one, Partytown synthesizes a synchronous DOM proxy that the worker can call. Every document.cookie read becomes a sync round-trip back to the main thread via a service worker plus a synchronous XHR. For a script that does ten DOM reads, that's ten cross-thread round-trips.
The latency cost is real but not the worst part. The worst part is that any script that listens for events, mutates the DOM, or interacts with iframes — chat widgets, heatmaps, A/B tools, ad scripts — either breaks or behaves strangely. The team running Partytown calls this out in their docs; it's not a bug, it's the inherent cost of running browser code outside the browser.
What defer-and-load gets right
Quickload doesn't sandbox anything. It lets the browser parse the page, parks the third-party script tags as inert MIME types, and then activates them — using the browser's native script loader — when a configurable trigger fires. document.currentScript.src stays correct. integrity survives. Vendor self-bootstrappers behave normally because the only thing that changed is *when* the browser executed the script.
Where sandboxing still has value
For pure measurement scripts that never touch the DOM — Plausible, a stripped-down GA4 send-only ping, custom analytics that just fetch() — running them in a worker is genuinely zero main-thread cost. We considered shipping a per-tag sandbox option for those, then dropped it: the support burden of maintaining two engines outweighs the marginal benefit, and a well-deferred script is good enough.