How To Improve Website Performance In 2023
Tags: webdev, javascript, performance, programming
Published: 2022-12-29 14:01:20

Are you tired of staring at your website's performance scores and feeling like you're stuck in a rut? You're not alone. It can be frustrating to try different suggestions for improving performance, only to see little or no improvement. But what if I told you that there's a way to automate the process of applying performance optimization suggestions and see which ones actually have an impact on your score? In this blog post, we'll share the results of our testing and show you how you can use tools like [WebPageTest](https://www.webpagetest.org) and [Performance insights](https://www.builder.io/c/performance-insights) to streamline the optimization process and take your website's performance to the next level. 

Both tools have an approach to experiment with how certain actions can improve performance scores. For example, WebPageTest has an “Opportunities & Experiments” tab:

![A screenshot from WebPageTest showing the results for Amazon.com. In it you can see the "opportunities & Experiments" section.](https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fcc1b2a310f8d4f25883fc849363c52f1?format=webp&width=2000)

On the bottom you have the experiments:

![A screenshot of "create experiments" from webpagetest.](https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F3426e10932de4eea9367205196cbe270?format=webp&width=2000)

In the experiments section, you can make modifications to different parts of your test:

1. **Adding HTML to the document:** for example, adding HTML to the start or end of `<head>` or alternatively adding HTML to the end of the `<body>` tag. This could be used for testing a JavaScript `<script>` tag in different places and seeing how it affects performance.
2. **Replacing text:**  for example, changing headings to see if it affects LCP.
3. **Delivery optimizations:** Defer Render-Blocking Scripts, Async Blocking Scripts, Load CSS Async, Add Image Aspect Ratio, etc., etc… (*caveat - you have to pay to run most experiments) 

Number 3 has the bulk and most if not all of the things that really have any effect on Google Lighthouse scores, which is what then becomes real user data that is gathered for the [Google Chrome User Experience Report](https://developers.google.com/web/tools/chrome-user-experience-report). 

## Let’s try this again

I’m sorry…

That was boring.

That is what happens when tools like GPT3 and AI get into the mix… 

It’s never been easier to make a machine spit out words.

What It lacks, is human creativity.

I’m gonna stop regurgitating what every other post about web performance and try and save us time and try to keep things simple, short, conversational, perhaps unorthodox, human if you will, and hopefully entertaining.

Including the writing.

Think of this as an experiment, and you’re a part of it ([LMK if you liked it or not](https://www.twitter.com/hamatoyogi)).

## Score-a-palooza


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lmahsgazvkbe64cgo8s6.gif)

Those scores? Lighthouse scores? they are also what determines a website’s visibility in search and the bottom line for a business.

## The formula is simple:

- When your [CWV](https://www.cloudflare.com/learning/performance/what-are-core-web-vitals/) scores are 📈
- 💰💰💰💰💰💰💰💰💰💰💰💰💰💰

Ergo:

- Performance 📉
- 💸  (bye-bye)

So, as developers, we want to achieve good performance for the apps we’re working on so that the business we work for will succeed and we will have a place that pays us to write code (or about code in some cases 😂).

### Full disclosure, I work at Builder.

(gotta work somewhere… or for yourself - yeah, yeah, yeah, y’all “WANTtrepreneurs” - did you ever try to do it yourself?! That s**t is hard!!! Sorry, I’ll get ahold of myself, cough. cough.)

..And we’re trying to help all of our customers succeed, and the developer community in general succeed.

That’s why we’ve made:

- [Partytown](https://partytown.builder.io/) (open source) for 3rd party code
- [Qwik](https://qwik.builder.io/) (open source) for 1st party code
- Visual CMS (the product that I am not linking to because that would be too promotional 😉) for 1st party content

What the above help with is making things easier, mostly in terms of performance for websites.  And of course, to make money 🤑. 

What? I just explained why.

Where was I…

Oh, helping with performance.

To do so, we need to measure.

## What do we measure?

Like I’ve said, Google already tells us! Core Web Vitals.

How do we measure it?

Tools, Like WebPageTest, Your browser, etc.

Some tools help automate some of the tedious work of running those tests.

There are probably others I’m forgetting that I will probably be reminded of in countless posts or tweets or whatnot either contradicting what I say or “you didn’t mention blah blah blah…”

Anyway, so WPT tool does a great job at running multiple tests instead of you needing to run lighthouse through dev tools 100 times and waste your time because your browser keeps crashing from all those extensions you got running that hog up your browser’s main thread anyways, all to help automate all those clicks you need to do just to run those tests because you’re a developer and you wasted 6 hours writing that PlayWright script, just because you wanted to try a new piece of tech…… 

I’m out of breath…

I can’t keep apologizing, so I’ll just keep going - gotta ship this before the new year!

## `</Rant>`

Nothing against WPT folks, they’re awesome and doing awesome work, and they need to get paid, like everyone, and that’s why they made the “experiments tab”. 

So, like I was saying, they do all the hoojmajaja that tries the different ways to optimize a web page.

Those are all of those hidden / not hidden edges of [MDN](https://developer.mozilla.org/en-US/) that you never got to or cared enough to read. All that hog podge about minifying code, serving images in the right format yada yada yada…

Enter [Performance insights](https://www.builder.io/c/performance-insights), the same idea just grouped a bit differently, and automatically runs experiments, then shows scores for all the scenarios.

The three most impactful areas for improving performance scores are: 

1. Images
2. CSS
3. JavaScript

Like, my buddy, [Steve](https://twitter.com/Steve8708) said (in his gen-z short from video that I might share with you if you actually read through 😜) if you do just 3 things, you can get a 95-100 score on LH, as well as have roughly a 2 second Time To Interaction. And as we know: 

> 📉 TTI ⇒ 📈 User Experience ⇒ 😃  Users ⇒ 💰
> 

## I guess gotta show you some stuff

[Here’s the file with numbers and graphs and s**t.](https://docs.google.com/spreadsheets/d/1acZc393_oamn4Ru-suQTJ7AeenJkB6foFYSz6LFUhgI/edit#gid=0) 

In the above list, we ran the `Performance Insight` tool on 50 of the most popular eCommerce sites.

Of course, no need to mention, actually, probably better that I do:

> `All measurements in the file are correct for the time of running the tests and may vary if you test now`

So these are the average scores, and you guessed it, red is 👎🏽, yellow 😑 , and green 👍🏽.

![A screenshot from the sheet that shows the average lighthouse score for the 50th top eCommerce sites.](https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fa460bef6f9f647f9ad7e4faf73981df9?format=webp&width=2000)

Here’s one example where you can see that optimizing images and CSS does nothing to improve the score.

That’s probably because those top 50 sites pay the good 💲 to top talent devs, and they already picked up that low-hanging fruit.

On the other hand, optimizing JavaScript will make the site go VROOOOOOM! 🏎️

![A screenshot of performance insights result, showing a 35 core web vital score for current, 35 CWV score for both cases of optimizing CSS and images, all with a 21 second time to interaction. on the right a 97 CWV score in green and a 2.3 second TTI if you optimize JavaScript.](https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fc41b95476a5a4473a4557f8895cb8a7b?format=webp&width=2000)

Images are basically a solved problem by most frameworks with a bespoke `<Image />` component for each, and by using providers such as [Cloudinary](https://cloudinary.com/) and the like.

For CSS, a lot of solutions can suffice, such as [Tailwind](https://tailwindcss.com/), [CSS Modules](https://github.com/css-modules/css-modules), etc. [But be wary of CSS in JS](https://dev.to/srmagura/why-were-breaking-up-wiht-css-in-js-4g9b) solutions like [Emotion](https://emotion.sh/docs/introduction) and [Styled Components](https://styled-components.com/).

## You got 99 problems and JavaScript is 83

Alright, you can see the image (or read the descriptive and accessible alt text 😅). 

I know you can see where the green is at. 

JavaScript is the language everyone loves to hate. That is the main monkey wrench that’s stuck in our wheels. It’s too bad that it’s what’s easiest for a developer to add, and the fastest way to f**k up your performance.

> “…shipping too much on JavaScript means you will be creating user experiences that are slow to load, sluggish to respond, and frustrating to users.” - [HTTP Archive’s Web Almanac](https://almanac.httparchive.org/en/2022/javascript)

And yet, we’re addicted to JavaScript. We ship a s**tload of it as you can see in  [The Web Almanac](https://almanac.httparchive.org/en/2022/javascript):

![Bar chart showing the 10, 25, 50, 75, and 90th percentiles of JavaScript kilobytes per page. On mobile pages, the values are 87, 209, 461, 857, and 1,367 KB respectively. Desktop values are slightly higher across the board.](https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F1ce82a108c604cffb2f8bbe8f95a682f?format=webp&width=2000)

If we shipped no JS, our lighthouse scores would go to the moon! 🚀

The number of bytes in the 90th percentile is 🤯. And these numbers are rising every freaking year. 

Yet there are things you can do to minimize the amount of JS we ship and to improve JS load time, but the fact of the matter is that most websites don’t bother.

A simple thing for example is **not** putting script tags in the `<head>` tag, cuz that’ll block your rendering, and still, 77% of websites make that mistake.

We also seem not to care who we bring inside our house and that they came in with mud, 💩, and cookies.

The number of 3rd party scripts on web pages is staggering! Seems like marketing and product folks don’t tell devs how many things they stick into GTM. Have a look:

![Bar chart showing the 10, 25, 50, 75, and 90th percentiles of JavaScript requests per mobile page, broken down by whether the script was served by a first- or third-party host. The values for both are nearly identical, at 2, 4, 10, 20, and 34, respectively.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fiahm6yq6jhd14n461kz.png)

And can you guess how much 3rd party code is compared to 1st party code?

I can’t even find the right words to express how absurd these numbers are:

![Bar chart showing the 10, 25, 50, 75, and 90th percentiles of kilobytes of JavaScript loaded per mobile page, broken down by whether the script was served by a first- or third-party host. The values for third-parties are 34, 109, 292, 595, and 1,003 KB per page, respectively. First-party scripts are much lower, at 20, 65, 109, 309, and 642 KB per page.](https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fe05bcc3ad84a48c2b1b4eff92da3bffc?format=webp&width=2000)

### A quick fix for 3rd party scripts - Partytown

The thing that can reign in your data-mongering product managers and marketing managers is [Partytown](https://partytown.builder.io/). 

It puts those scripts in the corner to wait and cry like an annoying little child that keeps disrupting class. Technically, it puts them in a web worker and takes them off the main thread, so maybe it’s not putting them in a corner, but moving them to a different classroom for a while until they relax.

### What about my code?

Let’s face it, we still need to write JavaScript.

How else would we do that super unnecessary animation that collapses a 3d rendered header that is hooked up to your scroll position and at 50% scroll height opens up the newsletter popup?

We need interactions. Users want them, and we like to build them.

So for:

- More Interactions 📈
- Less JS 📉

Try: 

- [Astro](https://astro.build/)
- [Marko](https://markojs.com/)
- [Solid](https://www.solidjs.com/)
- [Qwik](https://qwik.builder.io/)

## The bottom line.

Improving performance is hard. 

Each layer of the holy trinity (HTML/CSS/JS) at itself has tons of nuances.  

JavaScript is where you should focus on if you want the biggest bang for you buck.

Do your research. Measure. Try different things and measure again.

Got it?

Bet.

Play around with dem tools, they dope, no cap.

Hope this hits different 🙂 

Oh yeah, [here’s that TikTok link](https://www.tiktok.com/@steve8708/video/7102152947970264366?is_from_webapp=v1&item_id=7102152947970264366).