What is Partytown and how does it work?
mainPartytown is a lazy-loaded library designed to relocate resource-intensive third-party scripts (such as analytics, ads, and trackers) from the browser's main thread into a web worker.
By offloading these scripts, Partytown frees up the main thread to focus exclusively on your primary web application execution, improving responsiveness and performance. It achieves this by:
- Sandboxing: Controlling access to main thread APIs.
- Isolating Tasks: Running long-running third-party tasks in a separate thread.
- Batching DOM Operations: Reducing layout thrashing by grouping DOM setters and getters.
- Synchronous Simulation: Reading and writing main thread DOM operations synchronously from within the web worker so that scripts execute as they were originally coded without alterations.