Dramatically improve website speed with Partytown

Beyond Fireship · Intermediate ·🌐 Frontend Engineering ·3y ago

Key Takeaways

This video demonstrates how to use Partytown to improve website speed by running non-essential scripts with a webworker, covering JavaScript and web development techniques.

Full Transcript

on the web performance is everything if your website is slow and janky you are going to lose money that's a fact that's been proven by science what sucks is that it's often not your fault that your website is slow what happens is your first boss tells you you need to add Google analytics then your second boss wants to add Facebook pixel and boss number three wants to add an intercom chat widget all these tools require JavaScript and will clog up the main thread on the initial page load when you run a lighthouse report you'll get a very high blocking time because all these scripts are competing to work on the main thread and sadly the person who gets blamed for this poor performance is you the developer while your bosses get nice big Christmas bonuses luckily though there's a new open source Library called Party Town that can make everybody happy by running these scripts synchronously in a web worker and in this video you'll learn exactly how to use it to get started I want to demonstrate the problem very clearly as you can see here I have an HTML page with a script in the body you can imagine this script as a third-party resource that will harvest the personal information of your users in order to serve them advertisements that will more effectively separate rate them from their money in the script we have a while loop that does nothing for a while and what you'll notice is that if we run a lighthouse report everything looks good except for this one render blocking activity it says we need to reduce the JavaScript execution time this is actually a really Insidious performance problem because what happens is the page content will load but nothing is interactive that means if people try to click on buttons that require JavaScript they just won't work it's like a zombie website and by the way Party Town comes from the same team behind the quick framework and those guys are absolutely obsessed with performance the way it works is it designates scripts that are not essential to the initial page load such as marketing tools like Google tag manager and Facebook pixel or optional widgets like intercom and moves them over to a webworker you see JavaScript is single threaded which means it can only do so much at one time webworkers are a way to take non-essential things and run them in the background on a totally separate thread let's go ahead and see it in action I'm running a vanilla JS project here with Veet and the first thing I'll do is install the party town library once that's done we can find any scripts that we don't want to block the main thread and change them to type text Party Town this is how you designate what should run in a webworker once that's done they have integration guides for all kinds of different Frameworks like nexjs next and spill kit so you'll want to follow the guide for your framework in my case though I'm using vanilla JS now one thing that's unique about this library is that it uses a service worker which means it can't be hosted on an external CDN that means you'll need to copy and host its JavaScript code alongside your website luckily it provides a utility to simplify this process if we go into the package Json file we can create a script called Party Town that runs this copy lib command that will copy all the necessary code into the public directory go ahead and run that command from the terminal and you should now see all the Party Town files in the public directory and that brings us to our final step where we actually run Party Town it recommends that you inline the script directly into your code again there are Integrations for all the major Frameworks but in vanilla.js what I'm doing is creating a module script then importing the Party Town snippet from the library that's the code we want to inline so I'm creating a new script element in the Dom then using the snippet as the inner text and finally we append that script to the body to run it that takes care of that and I'll also point out that if you want to add any config options to Party Town you can create an additional script above it to handle things like forwarding for Google tag manager and now if we run the application through another Lighthouse performance analysis you can see we get a nearly perfect score with zero milliseconds of blocking JavaScript that's great news for the end user but even better news for you the developer because now people will stop blaming you for those horrible performance scores thanks for watching and I will see you in the next one

Original Description

Learn how to use Partytown to run non-essential scripts with a webworker and dramatically improve your websites speed and rendering performance. https://partytown.builder.io #javascript #webdevelopment
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Beyond Fireship · Beyond Fireship · 17 of 42

1 Social Media Style Number Formatting in JS
Social Media Style Number Formatting in JS
Beyond Fireship
2 I used 3 different File System APIs in Node.js
I used 3 different File System APIs in Node.js
Beyond Fireship
3 Time is Relative, even in JavaScript
Time is Relative, even in JavaScript
Beyond Fireship
4 How to NOT Screw Up Firebase Environment Variables
How to NOT Screw Up Firebase Environment Variables
Beyond Fireship
5 How to make your JavaScript Bundle Smaller
How to make your JavaScript Bundle Smaller
Beyond Fireship
6 Subtle, yet Beautiful Scroll Animations
Subtle, yet Beautiful Scroll Animations
Beyond Fireship
7 Beyond Surreal? A closer look at NewSQL Relational Data
Beyond Surreal? A closer look at NewSQL Relational Data
Beyond Fireship
8 How to Build a Discord Bot
How to Build a Discord Bot
Beyond Fireship
9 How to make Eyeballs that Follow You Around
How to make Eyeballs that Follow You Around
Beyond Fireship
10 Reverse Engineer Google’s NASA Dart Easter Egg with CSS
Reverse Engineer Google’s NASA Dart Easter Egg with CSS
Beyond Fireship
11 Generate Images Programmatically on the Edge
Generate Images Programmatically on the Edge
Beyond Fireship
12 WTF are all these config files for?
WTF are all these config files for?
Beyond Fireship
13 NEW Firebase Features Just Dropped
NEW Firebase Features Just Dropped
Beyond Fireship
14 Next.js 13 - The Basics
Next.js 13 - The Basics
Beyond Fireship
15 Make Crazy Art with the NEW OpenAI Dall-e API
Make Crazy Art with the NEW OpenAI Dall-e API
Beyond Fireship
16 How to Setup Node.js with TypeScript in 2023
How to Setup Node.js with TypeScript in 2023
Beyond Fireship
Dramatically improve website speed with Partytown
Dramatically improve website speed with Partytown
Beyond Fireship
18 The easiest realtime app I’ve ever built
The easiest realtime app I’ve ever built
Beyond Fireship
19 10 Rendering Patterns for Web Apps
10 Rendering Patterns for Web Apps
Beyond Fireship
20 You don't need Node to use NPM packages
You don't need Node to use NPM packages
Beyond Fireship
21 Sorting Algorithms Explained Visually
Sorting Algorithms Explained Visually
Beyond Fireship
22 ChatGPT Official API First Look
ChatGPT Official API First Look
Beyond Fireship
23 I built an image search engine
I built an image search engine
Beyond Fireship
24 Industrial-scale Web Scraping with AI & Proxy Networks
Industrial-scale Web Scraping with AI & Proxy Networks
Beyond Fireship
25 Next.js Server Actions...  5 awesome things you can do
Next.js Server Actions... 5 awesome things you can do
Beyond Fireship
26 The ultimate guide to web performance
The ultimate guide to web performance
Beyond Fireship
27 I built a fullstack PaLM AI app in just 2 minutes
I built a fullstack PaLM AI app in just 2 minutes
Beyond Fireship
28 I tried 8 different Postgres ORMs
I tried 8 different Postgres ORMs
Fireship
29 I built a *streaming* AI chat app
I built a *streaming* AI chat app
Fireship
30 React VS Svelte...10 Examples
React VS Svelte...10 Examples
Fireship
31 How GitHub Actions 10x my productivity
How GitHub Actions 10x my productivity
Fireship
32 PROOF JavaScript is a Multi-Threaded language
PROOF JavaScript is a Multi-Threaded language
Fireship
33 Mind-blowing page animations are easy now... View Transitions API first look
Mind-blowing page animations are easy now... View Transitions API first look
Fireship
34 I built an Apple Vision Pro app... visionOS tutorial
I built an Apple Vision Pro app... visionOS tutorial
Fireship
35 This UI component library is mind-blowing
This UI component library is mind-blowing
Fireship
36 How I deploy serverless containers for free
How I deploy serverless containers for free
Fireship
37 GitHub Copilot now controls your command line...
GitHub Copilot now controls your command line...
Fireship
38 Build better payment forms using new “embedded” Stripe Checkout
Build better payment forms using new “embedded” Stripe Checkout
Fireship
39 Does Deno 2 really uncomplicate JavaScript?
Does Deno 2 really uncomplicate JavaScript?
Fireship
40 JavaScript performance is weird... Write scientifically faster code with benchmarking
JavaScript performance is weird... Write scientifically faster code with benchmarking
Fireship
41 Is Next.js 15 any good? "use cache" API first look
Is Next.js 15 any good? "use cache" API first look
Beyond Fireship
42 I built a DeepSeek R1 powered VS Code extension…
I built a DeepSeek R1 powered VS Code extension…
Fireship

This video teaches how to use Partytown to run non-essential scripts with a webworker, resulting in improved website speed and rendering performance. By applying these techniques, developers can significantly enhance their website's user experience.

Key Takeaways
  1. Install Partytown
  2. Identify non-essential scripts
  3. Configure webworker
  4. Test and optimize performance
  5. Deploy optimized website
💡 Using Partytown to offload non-essential scripts to a webworker can dramatically improve website speed and rendering performance.

Related Reads

Up next
How to Speed Up Your WordPress Website with WP Rocket ⚡Tutorial 2026
Matt Tutorials
Watch →