37 Theses on CSS and Web Development
Published on AugĀ 16, 2018 (updated SepĀ 23, 2023), filed under development, css (feed). (Share this on Mastodon orĀ Bluesky?)
Just like my other little books, CSS Optimization Basics ends with a list of key ideas that serve to summarize the book, and that may be useful outside of it, too.
CSS optimization is important because we, especially as individuals, donāt always write perfectly efficient, understandable, and maintainable code.
Writing quality code, however, is what makes us professionals.
CSS optimization does not entail āeverythingā that can be done with a style sheet; it entails what makes it more efficient, understandable, and maintainable, while looking for a good balance.
As professionals, we benefit from doing one (or two, or three, but not eighty-five) things really, really well; as web developers, itās a good idea if CSS is one of those things.
Itās useful when we know our needs.
Itās sound when we develop for the present.
It makes our work easier when we keep it simple.
Thereās nothing wrong with doing less workāby automating more of it.
Thereās nothing wrong, either, with not doing any work, of a certain typeāby automating all of it.
(Thereās much wrong with not doing important work because we havenāt yet managed or automated the unimportant work.)
Code should be understandable and for that, itās useful when itās consistent and simple.
Consistent CSS is founded on alphabetical declaration sorting (everything else is too complicated) and on a robust order for selector sorting.
Simple CSS uses functional or generic names or avoids IDs and classes altogether.
Simple CSS also likes shorthands (yes).
Speed is important.
Selector performance doesnāt matter, and inline CSS is a crime.
(Web development is not software development.)
Some declarations may be slower than others but thereās rarely reason for panic.
Rule hygiene may be most important for CSS performance.
The most basic way to determine quality is through validation, and high error counts mean low quality scores.
Every piece of code gets at least touched twice.
For these last two observations, maintainability and maintenance are critical.
!important
is not an obstacle to maintenance; itās a tool.One of the most important principles is separation of concerns. Content, structure, presentation, behavior are different concerns.
In code, we donāt want to repeat ourselves.
Accordingly, in CSS, we want to limit the repetition of declarations.
Optimization for production is an important second step because, in production, machines use our code whereas, in operation, humans use it.
When we cannot production-optimize automatically, we should do as much as we can manually, as part of our craft.
For production, we remove all unneeded characters. All of them.
We typically want to reference one style sheet that includes all styles, though there are cases of high complexity where a modular approach leads to better performance.
(We cannot be absolved from thinking and making decisions about our projects.)
(Exceptions prove the rule.)
We regularly review our CSS, both pre-production and in production.
We are professionals.
As professionals, we feel responsible, we hold ourselves accountable, and we set high ethical standards for ourselves.
And, as professionals, we lead by example.
If you like this or are curious, get yourself a copy of the book!
About Me
Iām Jens (long: Jens Oliver Meiert), and Iām a web developer, manager, and author. Iāve been working as a technical lead and engineering manager for companies youāve never heard of and companies you use every day, Iām an occasional contributor to web standards (like HTML, CSS, WCAG), and I write and review books for OāReilly and Frontend Dogma.
I love trying things, not only in web development and engineering management, but also in other areas like philosophy. Here on meiert.com I share some of my experiences and views. (I value you being critical, interpreting charitably, and giving feedback.)