Bence Meszaros
3 min readSep 23, 2024

--

Thank you for your response.

I specifically asked about "loading alongside the HTML", because you stated, that "parsing and executing CSS is much faster than JS, because CSS is loaded alongside the HTML, meanwhile JS parsing and execution are render-blocking" and in this statement you mix up loading, parsing, execution and rendering, and this is what I wanted to untangle so that we wouldn't compare apples to oranges.

The browser has to load HTML, CSS and JS to function. Loading starts with HTML, then the browser can load further resources, including CSS and JS. In this regard, the two languages work exactly the same.

Then, the browser needs to parse and execute both CSS and JS, but they are quite the same in this too. I haven't found a metric in this regard, you only provided half of this comparison, and even that is an appeal to authority fallacy (according to someone "building the CSSOM is very, very fast", and we don't even know what "very fast" mean). I can argue, that parsing and executing JS is also very, very fast, even comparable to C: https://jyelewis.com/blog/2021-09-28-javascript-is-fast/. I, personally, have never measured the two side-by-side, but my argument is that by increasing the amount of JS while decreasing the amount of CSS we can achieve the same overall performance as we would by decreasing JS and increasing CSS. So more JS doesn't mean worse performance.

Lastly, CSS is render blocking (https://web.dev/articles/critical-rendering-path/render-blocking-css), but anything async in JS is not. In this regard, the comparison is still a bit apples to oranges, since JS can accomplish much more than CSS. My argument here is that if you need even just a bit of JS functionality, then it would only be logical to consider moving over to JS entirely and ditch CSS, since JS can achieve everything CSS can, but CSS cannot achieve everything JS can (by far), thus you can achieve much better code consistency (among a ton of other benefits as I mentioned earlier).

We can also discuss how poorly written CSS compares to poorly written JS but that too would be a false comparison and I am not even sure that a fair comparison would even theoretically be possible.

So, how do I apply styles, then? It is an excellent question, I manipulate the DOM directly, without writing any CSS code. I also don't use CSS selectors, since all my Views are created directly in JS so I already have a reference to each and every DOM node (thus I can sidestep HTML too). An added benefit is that there is no performance penalty when "querying" Views.

Here is a simple example (Medium strips formatting, but you can get the idea):

let myView = Text("Hello, World!")

.fontFamily("Helvetica")

.opacity(0.3)

.center(parent.center)

.middle(parent.middle);

No HTML, no CSS to load, parse and execute, only pure JS. If you are interested you can read more about how I think we could eliminate writing HTML (https://medium.com/@decketts/rip-html-rip-797bd9685c95), and the same for CSS (https://medium.com/@decketts/designing-a-new-style-system-to-replace-css-182d68d2d11b).

As for saying that "it is the first time I see someone that actually hates CSS" is kind of a fallacy too. My feelings are completely irrelevant in this context, just as their popularity. They don't prove or disprove anything. My argument is that CSS is a bad language because it constantly violates its own basic rules as I have demonstrated in many of my articles.

Once again, I am writing all this, because I believe that your original statements are not correct, and JS doesn't perform worse than CSS in a fair comparison. It doesn't really matter if I convince you or not, I am merely pointing this out so that others won't feel stigmatized (incorrectly) for using JS.

--

--

Bence Meszaros
Bence Meszaros

Written by Bence Meszaros

Lead Software Engineer, Fillun & Decketts

No responses yet