Loading and running scripts in a worker thread
One of the Next.js Script
strategy options is worker
, which loads and runs the script in a web worker. In current Next.js versions, this is achieved via a library called Partytown (https://partytown.builder.io/). The following is from the Partytown documentation:
“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.” Partytown home page – https://partytown.builder.io/
To expand on that definition, JavaScript runs in a single-threaded environment in the browser. “Single-threaded” means we only have one entity able to execute compute operations; non-asynchronous work cannot be done in parallel. The main thread in this context is the browser’s JavaScript execution thread. When loading and executing...