← Back to context

Comment by Incipient

11 hours ago

As long as css remains "so fast it's free" then I'm mostly happy with that - I use css without thinking about optimisations, and I like it like that!

You can certainly write slow CSS, and people do :-) JavaScript typically takes up more of the CPU time overall, though.

Well, you can actually write slow css if you make real deep nested flex container. And it's not even too rare. You can actually find such example in yhe wild.

The spec of flex layout requires it to layout its child elements several times to compute actual layout. Make it deep and nested without proper constrains will results in n*n*n*n… layout computations and bring down the browser on resize.

  • It’s not even that hard. Use flex for layout and you can instantly see how slow reflow becomes when resizing the window.

It's not free at all. You can profile it with debug tools and find the most expensive selectors to refactor them. You can also write CSS animations that impacts performance/user experience, this can also be profiled.

Sorry but if you use advanced feature and especially on a big DOM, you have to think about optimisations.