February 22 2025
The Real Cost of JavaScript on the Frontend
How to leave the shallow bundle-size conversation behind and see the full cost of downloading, parsing, executing, and competing for the main thread.
Andrews Ribeiro
Founder & Engineer
4 min Intermediate Frontend
Track
Senior Frontend Interview Trail
Step 11 / 15
The problem
A lot of frontend performance discussion stops too early at bundle size.
Then the analysis becomes:
- large file is bad
- small file is good
That helps a little.
But it is still incomplete.
Because JavaScript does not stop costing once the download finishes.
Mental model
Think about JavaScript cost in at least five stages:
- download
- parse
- compile
- execute
- compete with the rest of the browser work
That “rest of the browser work” includes:
- input
- layout
- paint
- hydration
- other tasks and microtasks
That is why a page can:
- appear
- look ready
- and still respond badly to a click
Breaking the problem down
Network is only the beginning
If the file is large, of course download matters.
But on many real machines the strongest cost continues after that:
- the browser still has to understand the code
- prepare what is going to run
- execute the work
On weaker devices, this cost becomes even more visible.
Execution competes for the main thread
On the frontend, JavaScript usually shares the main thread with important parts of the experience:
- responding to events
- calculating layout
- painting the screen
If the script occupies too much time, the user feels:
- delayed clicks
- odd scrolling
- a stuck interface
Not because the internet was bad.
But because the browser CPU was too busy.
Hydration amplifies the cost in some apps
When the page arrives with server-side HTML, many people conclude that “it is already fast.”
But hydration also charges:
- download script
- execute script
- attach behavior
In a heavy app, HTML appears early, but interactivity still takes time.
A lot of JavaScript also costs maintainability
It is not only technical performance.
The more code in the client:
- the more state bugs can appear
- the more mismatch surface exists
- the more browser-side debugging work shows up
- the more work happens in each navigation or interaction
Less relevant JavaScript is not only optimization.
It can also be product simplification.
Simple example
Imagine two pages.
Page A:
- HTML appears quickly
- but it downloads a huge bundle to hydrate everything
- when you click, the screen reacts late
Page B:
- sends less script
- hydrates only the necessary parts
- interacts better even with a similar initial appearance
If you look only at “the HTML appeared,” the two may look equivalent.
If you look at real JavaScript cost, you notice the second one delivers a better experience.
Common mistakes
- Measuring only bundle size and ignoring execution.
- Assuming good network cancels out JS cost.
- Treating hydration as free.
- Moving everything to the client for convenience and calling that architecture.
- Judging performance without considering average or weaker devices.
How a senior thinks about it
People with more experience usually ask:
How much JavaScript do I really need to send, and how much work do I really need to do on the client?
That question is strong because it attacks two cost sources at the same time:
- unnecessary bytes
- unnecessary execution
Instead of only compressing excess better, it questions the excess itself.
What the interviewer wants to see
In interviews, this topic separates people who understand the browser from those who only look at the network.
Your level rises when you:
- talk about CPU beyond download
- mention parse, execution, and the main thread
- connect hydration to interactivity
- show that reducing JS is also reducing work
A strong answer often sounds like this:
JavaScript costs network, but it also costs a lot in parse, execution, and competition for the main thread. That is why a page with too much script can stay slow even when the HTML appears early and the connection is good.
The JavaScript problem on the frontend is not always downloading too much. Very often it is making the browser work too much.
Quick summary
What to keep in your head
- JavaScript costs network, but it also costs CPU and main-thread time.
- A large bundle does not cost only download. It also costs parse, compilation, execution, hydration, and more work competing with input and rendering.
- A page can feel slow even on good internet when the browser spends too much time processing script.
- Reducing JavaScript cost is about sending less and also doing less on the client.
Practice checklist
Use this when you answer
- Can I explain why JS may delay interactivity even when HTML is already visible?
- Do I know how to separate network cost from CPU cost in the browser?
- Can I connect hydration and excessive script to input lag and jank?
- Can I explain why less relevant JS is often better than a merely compressed bundle?
You finished this article
Part of the track: Senior Frontend Interview Trail (11/15)
Share this page
Copy the link manually from the field below.