Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@builder.io/partytown
Advanced tools
Relocate resource intensive third-party scripts off of the main thread and into a web worker.
@builder.io/partytown is a JavaScript library that helps move resource-intensive operations from the main thread to web workers. This can significantly improve the performance of web applications by offloading tasks such as third-party scripts, analytics, and other heavy computations to a background thread.
Offloading Third-Party Scripts
This feature allows you to offload third-party scripts to web workers, reducing the load on the main thread and improving page performance. The code sample initializes Partytown and forwards specific functions to the web worker.
import { init } from '@builder.io/partytown';
init({
forward: ['dataLayer.push'],
});
Web Worker Communication
Partytown enables seamless communication between the main thread and web workers. The code sample demonstrates how to forward a custom function to be executed in a web worker.
import { init } from '@builder.io/partytown';
init({
forward: ['myCustomFunction'],
});
function myCustomFunction() {
console.log('This runs in a web worker');
}
Improving Performance
By offloading resource-intensive tasks to web workers, Partytown helps improve the overall performance of your web application. The code sample shows how to forward a heavy computation function to a web worker.
import { init } from '@builder.io/partytown';
init({
forward: ['heavyComputation'],
});
function heavyComputation() {
// Some resource-intensive task
}
Comlink is a library that simplifies the use of WebWorkers by providing a proxy-based interface for communication. Unlike Partytown, which focuses on offloading third-party scripts, Comlink is more general-purpose and can be used for any kind of task that you want to run in a web worker.
Workerize is a library that automatically moves a module into a WebWorker and returns a proxy to interact with it. It is similar to Partytown in that it helps offload tasks to web workers, but it does not specifically target third-party scripts.
Greenlet is a library that allows you to run a function in a WebWorker and return a promise for its result. It is lightweight and easy to use, but it does not offer the same level of integration for third-party scripts as Partytown.
A fun location for your third-party scripts to hang out
Partytown is a lazy-loaded library to help relocate resource intensive scripts into a web worker, and off of the main thread. Its goal is to help speed up sites by dedicating the main thread to your code, and offloading third-party scripts to a web worker.
Note: Partytown is still in beta and not guaranteed to work in every scenario. Please see our FAQ and Trade-Off sections for more info.
The philosophy is that the main thread should be dedicated to your code, and any scripts that are not required to be in the critical path should be moved to a web worker. Main thread performance is, without question, more important than web worker thread performance.
FAQs
Relocate resource intensive third-party scripts off of the main thread and into a web worker.
The npm package @builder.io/partytown receives a total of 199,255 weekly downloads. As such, @builder.io/partytown popularity was classified as popular.
We found that @builder.io/partytown demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 23 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.