Partytown: Run Third-Party Scripts off the Main Thread in a Web Worker

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 …


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’s Proxy 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!


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Partytown: Run Third-Party Scripts off the Main Thread in a Web Worker." Bramus! | Sciencx - Monday September 27, 2021, https://www.scien.cx/2021/09/27/partytown-run-third-party-scripts-off-the-main-thread-in-a-web-worker/
HARVARD
Bramus! | Sciencx Monday September 27, 2021 » Partytown: Run Third-Party Scripts off the Main Thread in a Web Worker., viewed ,<https://www.scien.cx/2021/09/27/partytown-run-third-party-scripts-off-the-main-thread-in-a-web-worker/>
VANCOUVER
Bramus! | Sciencx - » Partytown: Run Third-Party Scripts off the Main Thread in a Web Worker. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/27/partytown-run-third-party-scripts-off-the-main-thread-in-a-web-worker/
CHICAGO
" » Partytown: Run Third-Party Scripts off the Main Thread in a Web Worker." Bramus! | Sciencx - Accessed . https://www.scien.cx/2021/09/27/partytown-run-third-party-scripts-off-the-main-thread-in-a-web-worker/
IEEE
" » Partytown: Run Third-Party Scripts off the Main Thread in a Web Worker." Bramus! | Sciencx [Online]. Available: https://www.scien.cx/2021/09/27/partytown-run-third-party-scripts-off-the-main-thread-in-a-web-worker/. [Accessed: ]
rf:citation
» Partytown: Run Third-Party Scripts off the Main Thread in a Web Worker | Bramus! | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.