This content originally appeared on Bram.us and was authored by Bramus!
The folks from builder.io set out to create a way to prevent Third-Party Scripts from block 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,
localStorage
,userAgent
, etc. Because the code must go through Partytown’sProxy
in 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.
It works by creating JavaScript Proxies to replicate and forward calls to the main thread APIs (such as DOM operations) and making calls to them using synchronous XHR requests. Pretty crazy, right?! ?
To mark third-party scripts to run in a Partytown web worker, set the type attribute of its opening script tag to text/partytown
.
<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 →
This content originally appeared on Bram.us and was authored by Bramus!
Bramus! | Sciencx (2021-09-27T22:12:41+00:00) Partytown: Run Third-Party Scripts off the Main Thread in a Web Worker. Retrieved from https://www.scien.cx/2021/09/27/partytown-run-third-party-scripts-off-the-main-thread-in-a-web-worker/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.