Skip to content

Guide · Open source

How to use Partytown: move third-party scripts off the main thread

Updated · written with AI from the project's own documentation and checked against our catalogue data

Partytown is an open-source JavaScript library that relocates resource-intensive third-party scripts, such as analytics or marketing tags, into a web worker. This guide explains what it does, when it fits a site, how to get started and where its limits are. By the end, you will know whether Partytown suits your pages and where to look next for setup details.

PartytownQwikDev/partytown · ★ 13.8k · MIT

Quick start

  1. 1Decide if Partytown fits. Confirm that your slow pages are caused by third-party scripts such as analytics or marketing tags, and that those scripts do not need to run on the main thread.
  2. 2Read the FAQ and trade-offs. Review the project's FAQ and trade-offs pages, since the README says Partytown is not guaranteed to work in every scenario.
  3. 3Clone the repository. Run the clone command from the README to get the source: git clone https://github.com/QwikDev/partytown.
  4. 4Follow Getting Started. Open the official Getting Started guide at partytown.qwik.dev/getting-started and follow the setup steps for your project.
  5. 5Check your integration. If you use a framework with a Partytown integration, follow the integrations page to connect it.
  6. 6Measure the change. Compare Core Web Vitals or Lighthouse results before and after enabling Partytown, and confirm your third-party scripts still work.

What Partytown does and why it matters

Partytown is a lazy-loaded library that helps move resource-intensive scripts into a web worker and off the browser's main thread. A web worker runs in a separate background thread, so these scripts compete less with your own code for the main thread.

The stated goal is to speed up sites by dedicating the main thread to your code and offloading third-party scripts to a web worker. The project's philosophy is that scripts not required in the critical path should move to a web worker.

  • Typical targets: analytics and marketing third-party scripts
  • Main benefit: less main-thread competition, which can help page responsiveness
  • Relevant metrics teams track: Core Web Vitals and Lighthouse scores

Check whether Partytown fits your site

Partytown is a good match when your pages are slowed by analytics or marketing scripts, or when you are working to reduce main-thread work. It is also aimed at developers using a framework that has a Partytown integration; the project's README links an integrations page for this.

It is not a fit when your third-party scripts must run on the main thread. The README states that Partytown is not guaranteed to work in every scenario, so read the project's FAQ and trade-offs pages before you commit.

  • Good fit: slow pages caused by analytics or marketing tags
  • Good fit: teams measuring Core Web Vitals or Lighthouse
  • Poor fit: scripts that must run on the main thread
  • Poor fit: teams needing a guaranteed, fully supported setup without reviewing the trade-offs

Get the project and its getting-started guide

The README lists a clone command for the repository. The project's documentation site hosts the Getting Started guide, which covers setup in more detail than the README excerpt.

The README does not list any prerequisites, so check the Getting Started page for the setup requirements that apply to your project.

  • Homepage and docs: https://partytown.qwik.dev
  • Getting Started guide: https://partytown.qwik.dev/getting-started
  • Integrations page: https://partytown.qwik.dev/integrations
  • Configuration page: https://partytown.qwik.dev/configuration
git clone https://github.com/QwikDev/partytown

Choose an integration or configure it yourself

If your framework has a Partytown integration, start from the integrations page. Configuration options are documented on the configuration page, so you can adjust Partytown to your site after the basic setup works.

The README does not describe the exact configuration steps, so rely on the official docs for those details rather than guessing.

  • Check the integrations page first if you use a supported framework
  • Use the configuration page to tune settings once the basics run

Test the results and review the trade-offs

After setup, measure the page again. The project's own illustration shows your code and third-party code competing for main-thread resources without Partytown, which is the problem it targets. Compare your Core Web Vitals or Lighthouse results before and after to see whether it helped.

Some third-party scripts may behave differently in a worker. Review the FAQ and trade-offs pages and confirm that each relocated script still works as expected.

  • Measure before and after with the same test conditions
  • Verify that analytics and marketing tags still fire correctly
  • Read the trade-offs page before moving critical scripts

What people use it for

  • Moving analytics tags off the main thread on a content site that feels slow to respond
  • Offloading marketing scripts on a landing page while keeping the page's own code responsive
  • Tracking Core Web Vitals or Lighthouse scores before and after reducing main-thread work

Frequently asked questions

Is Partytown free to use?

Partytown is released under the MIT licence, which is a permissive open-source licence. Check the LICENSE file in the repository for the full terms before using it in your project.

What does Partytown do?

Partytown is a lazy-loaded library that relocates resource-intensive third-party scripts, such as analytics or marketing tags, into a web worker. This frees the main thread for your site's code.

Does Partytown work with every site?

Not necessarily. The README states that Partytown is not guaranteed to work in every scenario, so check the FAQ and trade-offs pages before relying on it.

What are the requirements for Partytown?

The README does not list any prerequisites. Check the Getting Started guide at partytown.qwik.dev/getting-started for setup requirements.

How do I install Partytown?

The README gives a clone command, git clone https://github.com/QwikDev/partytown. For full setup steps, follow the official Getting Started guide on the project's documentation site.

Are there alternatives to Partytown?

The project does not list comparable projects in this source. You can evaluate other approaches to third-party script loading, but Partytown's stated goal is moving those scripts into a web worker.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Partytown suits site owners and teams whose pages are slowed by analytics or marketing scripts, especially if they use a framework with an integration. It is a poor choice if your third-party scripts must run on the main thread or if you need a guaranteed, fully supported setup without reviewing its FAQ and trade-offs first.

Install options & downloads