JavaScript Bloat: Why does it matter?
Tags: javascript, webdev, frontend
Published: 2023-06-21 08:51:33

Ever wonder why your website gradually slow down after each release? In the tech world, it is widely believed that the main culprit behind lies in what we call `JavaScript Bloat`.


## Table Of Contents
   
1. [State of JavaScript](#state-of-javascript)
2. [What is JavaScript Bloat](#what-is-javascript-bloat)
3. [Why more JavaScript mean Worse Performance](#why-more-javascript-mean-worse-performance)
4. [Summary](#summary)

## State of JavaScript

In today's fast-paced world, JavaScript has become an integral part of almost all modern websites, enabling rich and interactive website experiences.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/62hbyz1i4lc3fwhosqzc.png)

Think about the following:

- An interactive map that can display real-time traffic updates
- A slider/carousel that switches images every few seconds
- A video player that plays YouTube videos
- And more…

All of the above use JavaScript to achieve the desired functionality.

For the last 10 years, JavaScript's usage has been increasing substantially by every measure.

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

Stats from [HTTP Archive](https://httparchive.org/reports/state-of-javascript?start=2013_01_01&end=2023_01_01&view=list) shows an average based on thousands of tested websites for the past decade (HTTP Archive performs tests every month).

Its observed that 10 year ago the median page serves only **168.1 KB** of JavaScript (**107.2 KB** for mobile). Now that number has risen to **508.5 KB** (**468.7 KB** for mobile). Its gone up ~200% (~330% for mobile) in just a decade.



## What is JavaScript Bloat


JavaScript is like chocolate in a cake: it enriches the experience. But add too much and you'll spoil the taste.

---

**JavaScript Bloat** refer to a website that relies excessive amount on poorly optimized JavaScript.

---

A feature-rich, complex website in exchange for providing modern, interactive experience naturally going to have more assets that consume more users' resources, from CPU and GPU to memory and network.

According to [HTTP Archive](https://httparchive.org/reports/page-weight?start=2013_01_01&end=2023_01_01&view=grid), the median web page weight around 2.2 MB of data split across 71 HTTP requests. This is a huge increase from 800 KB average of 10 year ago.

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

JavaScript is the highest contributor to the significant increase in page weight behind images (and videos).


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0nqbcgirl8wey5ai8j3j.png)



## Why more JavaScript mean Worse Performance

To display a web page, the browser parses the HTML content to build the DOM. As soon as the parser comes across a `<script>...</script>` tag, it stops the DOM building, waits for the script to download, parses it, executes it and only then can it process the rest of the page.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7le1l37ki3846mmd2ysf.png)

Depending on how large each scripts is, especially on slower connections, there will be a significant delay before users will be able to see your HTML.

That's why the delayed time between first load and interactive has increasing steadily according to [HTTP Archive](https://httparchive.org/reports/loading-speed?start=2013_01_01&end=2023_01_01&view=list)

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


When your website have lots of third-party scripts, they'll block your own JavaScript and have a drastic effect on your web page performance.

Here is an example of a simple HTML website before and after install a 3rd-party plugin.

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


##Summary

It's true that JavaScript slow down our webpage. However, it doesn't mean that you shouldn't use JavaScript at all.
In the next article in this series, we’ll discuss some advanced techniques you can use to optimize your website.