The folks from builder.io set out to create a way to prevent Third-Party Scripts from blocking the main thread. The result is Partytown, which runs Third-Party Scripts Within a Web Worker.
Partytown is able to sandbox and isolate third-party scripts within a web worker and allow, or deny, access to main thread APIs. This includes Cookies,
userAgent, etc. Because the code must go through Partytown’s
Proxyin order to access the main thread, Partytown also has the ability to log every read and write, and even restrict access to certain DOM APIs.
To mark third-party scripts to run in a Partytown web worker, set the type attribute of its opening script tag to
<script type="text/partytown"> // Third-party analytics scripts </script>
Also comes with integrations for frameworks like React.
Partytown (GitHub) →
Introducing Partytown: Run Third-Party Scripts From a Web Worker →