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