News for hackers. Stuff that matters.
Re:JavaScript Bloat in 2024 by pier25 on Thursday February 22, 2024 @11:23PM (#39476945)
What's up with the React site?

This is embarrassing...

Re:JavaScript Bloat in 2024 by tjosepo on Thursday February 22, 2024 @11:59PM (#39477165)
You can see from the recording that it's downloading the same few files from Codesandbox over and over again, as the iframes used for the examples are being unloaded and reloaded on scrolls and because the author disabled caching.

The author could've scrolled forever and the number would've gone up indefinitely.

Re:JavaScript Bloat in 2024 by CompuIves on Friday February 23, 2024 @05:59AM (#39479161)
Exactly, the result would've been different if the author would not have disabled caching.

In this case it's because the iframes are loaded/unloaded multiple times, but we also spawn web workers where the same worker is spawned multiple times (for transpiling code in multiple threads, for example). In all those cases we rely on caching so we don't have to download the same worker code more than once.

Re:JavaScript Bloat in 2024 by pier25 on Friday February 23, 2024 @08:30AM (#39480329)
Wouldn't it be better if the code editors only activated if the user interacts with one?

Even with caching it's absurd to download so much JS for a feature that probably most users will not use. It's a docs site after all.

Re:JavaScript Bloat in 2024 by makepanic on Friday February 23, 2024 @02:54AM (#39478009)
Codesandbox is embedded for the code samples. If you not have cache disabled it will fetch from memory cache after the initial load and unload.
Re:JavaScript Bloat in 2024 by silverwind on Friday February 23, 2024 @07:01AM (#39479529)
Maybe they forgot some `memo` so it re-renders everything including iframes all the time.
Re:JavaScript Bloat in 2024 by danabramov on Friday February 23, 2024 @07:12AM (#39479616)
1) In React, re-renders don't destroy the DOM. So nothing would happen if iframes were re-rendered.

2) Rather, we intentionally unload interactive editor preview iframes to improve memory usage when you scroll away from them. We do load them again when you scroll up — and normally that would be instant because the code for them would get cached. But the author has intentionally disabled cache, so as a result they get arbitrarily high numbers when scrolling up and down.