Live data from Hacker News

The Debate Around “Do We Even Need CSS Anymore?”

css-tricks.com

41–50 of 67 posts

Re: The Debate Around “Do We Even Need CSS Anymore?”

#41
post #4

I've been using inline everything since templates (ejs) came into existence. Once you have templates you're only editing one location anyway. The biggest problem with CSS is it's really easy to add, and close to impossible to delete (detecting potential repercussions is hard). Sure there's performance issues, but most of the time your developer/maintenance time is worth the the extra bytes.

It's not actually that terrible, but then again it depends on what you're building I suppose.

Where I work, I made a fairly robust image diffing utility that runs using Selenium/WebDriver on all browsers that we support. Combined with a robust test suite of many different scenarios, we can make changes to our stylesheets with a pretty high amount of confidence that if anything changed, it'll fail the build.

Re: The Debate Around “Do We Even Need CSS Anymore?”

#42
post #19

>What is the alternative to CSS then? The alternative is inline styles. ... The idea is you apply styles to elements through JavaScript. But if you have a non-trivial app with thousands of elements across hundreds of pages, people will inevitably want to "tame", "organize", "consolidate", etc those inline styles into some coherent taxonomy to enforce consistency. Wherever and however the programmers decide to store t…

That's what our product, Elevate Web Builder, does. It uses special JSON control interface files to describe the element styling:

http://www.elevatesoft.com/manual?action=viewtopic&id=ewb2&t...

The benefit of using JSON is that a JS compiler can include it in the HTML loader for the JavaScript application, minimizing any more round-trips to the web server, and can treat the JSON as a "resource" that can be manipulated in an easier fashion than CSS at runtime. Furthermore, the JSON can be compressed/uncompressed using identifier compression, making it tiny compared to CSS.

CSS is perfect for web sites that primarily use static/dynamic HTML organized as pages. It's a bad fit for single-page JS applications that act more like traditional desktop/mobile applications.

Re: The Debate Around “Do We Even Need CSS Anymore?”

#43
post #36
post #27

In human history we always went through development loops. And I can tell you this: I was there when there was not much CSS, and certainly no preprocessors. CSS was the Next Big Thing on the table (not even 10 years ago, and div was the next big thing instead of table). There are reasons for CSS. Now that it's everywhere young people think it sucks. Because old code always sucks. But often it's not the technology tha…

In what universe did SQL ever go away? The growth of popularity of non-relational databases was a reflection of the emergence of a different applications and a different approach to development. The "hate" for SQL was indeed often misplaced, but the need for different kinds of databases was real. The schemas of SQL were powerful but sometimes cumbersome to developers who need to rapidly iterate on their applications.…

I don't know why this comment is being down-voted. Your comments are spot-on. See my reply below about our product Elevate Web Builder - I came to the exact same conclusions as you. In fact, version 1 of EWB did use CSS, and then I got rid of it this year in version 2. In a component-based architecture, all UI updates are typically dynamic, and pre-defined styles simply don't fit as well, other than to define the various default "states" of controls/elements. CSS is complete overkill.

Re: The Debate Around “Do We Even Need CSS Anymore?”

#44
post #25
post #19

>What is the alternative to CSS then? The alternative is inline styles. ... The idea is you apply styles to elements through JavaScript. But if you have a non-trivial app with thousands of elements across hundreds of pages, people will inevitably want to "tame", "organize", "consolidate", etc those inline styles into some coherent taxonomy to enforce consistency. Wherever and however the programmers decide to store t…

There's still some key differences between what this new JSON declared and Javascript distributed stylesheets would work. Mainly is that there is no more CSS Selector madness. You no longer need to have concepts such as selector specificity, nor the entire syntax around grabbing the correct selectors. Also you could then be able to logically follow the flow using traditional debugging methods rather than this mess wh…

Here's an example of a JS application that dynamically animates DOM properties using requestAnimationFrame:

http://www.elevatesoft.com:8081/panels/panels.html

It's a little slow on mobile, but pretty good on desktops, and could probably use some optimizations. The DOM transitions are animated at the of end of each change management cycle for a given UI element. That allows for layout management that occurs independently of what is going on in the DOM, treating the DOM updates as only a "controlled repaint".

Re: The Debate Around “Do We Even Need CSS Anymore?”

#45

> The idea is you apply styles to elements through JavaScript. Great. Now simply reading a page without JS will become impossible, let alone interacting with it.

So what? Reading a page without HTML5 will also mangle some pages, some pages in the 90's required vbscript. Technology isn't bad. It's been years since I've heard someone suggest that non-js support is something to design against. Laughable, really.

Re: The Debate Around “Do We Even Need CSS Anymore?”

#46
post #34

Its weird because I remember when no one knew about CSS, amd then suddenly everyone had to do it. I also remember separating JS and HTML being really important for everyone for many years, but now everyone is doing the opposite. It just goes to show that people can make a cargo cult about any general approach.

> Its weird because I remember when no one knew about CSS, amd then suddenly everyone had to do it.

That year was 1999. 1998 it was "a huge improvement" still being standardized. It was formalized in 1999 (iirc) and eventually we saw HTML4.01 which assumed it was ubiquitous.

Re: The Debate Around “Do We Even Need CSS Anymore?”

#47

Representing styles as executable code is a very poor idea. Suddenly you go from data you can inspect and play with to something you can just execute and take what you are given. The principle of least power is an incredibly important axiom of the web's architecture, and when people break it, lots of things become more difficult or impossible. If you don't like CSS, then by all means, propose a replacement – but plea…

Check out the format for an inline style:

    {
      background: "red",
      fontWeight: "bold"
    }
It's just a Javascript mapping from strings to strings. That's a very un-powerful language, and that's what React consumes.

Sure, you could generate this mapping with all sorts of arbitrary code, just like how you could generate CSS with all sorts of arbitrary code. But that doesn't make the style declaration itself any more powerful, much less an arbitrary executable.

Re: The Debate Around “Do We Even Need CSS Anymore?”

#48
post #26
post #14

Earlier quoted context omitted.

> One is that your page should work without javascript Universal rendering would send straight HTML with inline styles to the browser. And plenty of web applications need JS to function properly.

True. Doesn't address the userstylesheet problem though. Also, sending prerendered pages with inline styles causes a bandwidth problem. Your prerendered page is probably dynamic and uncacheable, but your stylesheet isnt. By using inline styles, you send tons of repetitive uncacheable styles over the network where you could have just used a stylesheet. If you need the power that a full general purpose programming lang…

If they're really that repetitive, then gzip should eliminate almost all of the bloat.

We also need to think about number of round-trips. If you're on an old phone on a 3G connection in India, the extra round-trip from requesting the HTML then requesting the CSS makes a difference.

I'm super interested about the performance aspect, too, but I feel like we need numbers to really go into detail. There's way too many factors at play here for the correct answer to be obvious.

Re: The Debate Around “Do We Even Need CSS Anymore?”

#49

You lose the benefits of style caching with inline or dynamically applied styles, and inlining makes each HTML payload larger. Also, applying virtually all of your styles with JavaScript, after the DOM has already finished loading, wastes CPU cycles and just feels like going against the grain of CSS to me. You make a few arguable gains with this technique, but I feel it might be throwing the baby out with the bathwat…

The payload probably won't increase as much as we'd think thanks to gzip, and you can apply the styles via server-side rendering rather than waiting for the JS to load.

We also need to consider the time from request to a ready page: if you're on an incredibly slow connection, then having the styles immediately rather than waiting on a second round-trip is a huge win. I agree that there are pros and cons, but some of the pros are actually in performance; it's not immediately clear which technique is more performant overall in what contexts.

Post reply on HN