New Launches & Product Reviews

Partytown: Moving Selected Scripts Without Losing Functionality

Understand Partytown's worker communication paths, integration requirements and compatibility checks before changing third-party script execution.

Partytown: Moving Selected Scripts Without Losing Functionality

Find the expensive work first

Third-party JavaScript can compete with rendering and input handling on the main thread. Before moving it, identify which script performs the expensive work and whether the application still needs it.

Removing an unused integration, loading it after a relevant interaction or reducing its configuration may be simpler than changing its execution environment. async and defer affect loading and scheduling; they do not automatically move script execution off the main thread.

What Partytown changes

Partytown runs selected scripts in a web worker and coordinates access to APIs that live on the main thread. It is opt-in: the documented script marker is type="text/partytown". DOM-related work still requires communication with the main thread. How Partytown works.

The documentation describes both a service-worker communication path and an Atomics-based path. SharedArrayBuffer and cross-origin isolation are therefore not unconditional requirements for every Partytown deployment.

If choosing the Atomics path, evaluate the necessary headers against embeds, sign-in windows and other cross-origin behavior. Do not add isolation headers without testing those flows.

Follow a complete integration

The official Next.js guide documents the Partytown component, selected script declarations, forwarding and serving the library files. It does not provide the previously shown withPartytown wrapper as a Next.js configuration API. Next.js integration.

A complete build must make the worker library assets available at the configured path. Verify their production URLs and content types, rather than relying only on a development server.

For a framework's experimental worker strategy, check that framework's current routing-mode support. An example for a Pages Router document is not automatically an App Router layout implementation.

Preserve the integration contract

Some scripts expose a global queue or function that application code calls before the library is ready. Configure the documented forwarding for those calls and test ordering.

Use a local stub or provider sandbox to verify events without sending fake customer activity to production analytics. Confirm that one action produces one event, that events wait for the required consent state and that SPA navigation behaves correctly.

Do not solve a compatibility problem by silently enabling tracking earlier or bypassing a user's choices.

Test limitations deliberately

Partytown documents tradeoffs around DOM-heavy integrations and cross-thread access. Interactive widgets, layout-sensitive scripts and scripts with unusual timing assumptions need individual testing. Tradeoffs.

Exercise load, navigation, interaction and teardown. Test a blocked worker asset, unavailable third-party host and slow device. Check the console and network, but also verify the business behavior: a missing callback may be a functional failure without a visible exception.

Measure the result honestly

Compare the same page, device, network conditions and interactions before and after the change. Record script work and responsiveness alongside whether the integration still behaves correctly.

Lab measurements can show a regression or improvement under those conditions. They do not establish field INP at the 75th percentile. No universal percentage improvement follows from enabling Partytown, and this article does not claim one.

Sardar Mukhshaf

Sardar Mukhshaf

Full-Stack & DevOps Engineer

I build scalable web applications, secure backend systems, and production-ready cloud infrastructure. My engineering focus spans interface design, API architecture, deployment pipelines, and observability. Follow for more deep dives into system architecture, performance engineering, and emerging technologies.

More from the practice

Keep the useful ideas close.

Follow new articles with your preferred RSS reader.

Open the RSS feed ↗