How Partytown's Sync Communication Works
Partytown relies on Web Workers, Service Workers, JavaScript Proxies, and a communication layer between them all.
- Scripts are disabled from running on the main thread by using the
type="text/partytown"
attribute on the<script/>
tag. - Service worker creates an
onfetch
handler to intercept specific requests. - Web worker is given the scripts to execute within the worker thread.
- Web worker creates JavaScript Proxies to replicate and forward calls to the main thread APIs (such as DOM operations).