catering to the impatient/ready, set, go!

published on:
July 04, 2008
comments

Maybe it's a trend, maybe it's just cheer luck or maybe it's just in my face a lot. But lately, there seems to have been quite some talk about page loads, rendering speed and file size in relation to front-end code. Things I usually care very little about, as I consider them mostly as problems from the past (especially when they are related to html and css files). But some people seem to disagree, as a few comments and an article by Jens Meiert will illustrate.

the illusion of speed

lean html and css

First off, there were three comments (by Terrence Wood, Denis Sokolov and Jordan Clark) I received on my blog which all brought up the speed/size problem. I wasn't really surprised to receive these comments as they were all given in a series of articles that speaks in favor of leaner css at the expense of more convoluted html, which is not a popular idea at all.

I was surprised at their arguments though, as they were not about the purity of html and semantics, but about file sizes and speed gains. Now I understand that extra structural elements increase DOM processing, page loads and traffic, but I always figured these additions were to be neglected. I still think so, unless I see some proof that tells me otherwise. I understand that you gain a little speed in trimming your html to perfection (as it needs to be reloaded for each new page, as opposed to css which is often cashed), but I fail to believe it will have any important impact on the user experience.

What worries me more is the way most people are looking at css. It's the garbage can of web development. A no man's land where no official rules apply and which often functions as a kind of black box. You throw it on your html and if the design comes out okay you've done a good job. And the smaller the file, the better. There is little to no talk about how to organize your css, either physically or (more importantly) on a conceptual level.

There is no care or worry about writing flexible and maintainable css, especially not when it makes a file bigger or even worse, has an impact on the html. I find that a sad thing, especially as there's not else to do with css at this time. Now is the time we should be worrying about how to improve our css files, how to make them easier to work with and how to protect them from becoming a complete mess when design changes are needed. Instead, we are talking about shaving of the final semi-colon to lose a couple of bytes.

invalidating html

What boggled and surprised me even more was an article written by Jens Meiert on invalidating html in order to save bytes and gain speed (as in lesser traffic = faster). Now I respect Meiert's articles on web-related issues a lot and in his article he does elaborate that this is an experts technique, but I really fail to see his point.

Meiert talks about shaving of quotation marks and the like, which will obviously save you a few bytes but will invalidate your html. Still, browsers will render your pages okay. But opposed to the comments above, I can actually think of ways where this might even slow down the rendering of a page (in the long term). Currently, browsers use draconian parsers to parse the html. This means that when they encounter syntax errors in the code, they will try to fix it to their best knowledge, allowing them to still render the code okay.

This sounds nice, but working like this doesn't make the parsers any easier or faster. Invalidating your code will only further the need for this kind of parsing, which isn't helping out web development as a whole at all. I can see the gain on a small scale, but from a long-term view it makes no sense to me whatsoever. I can only hope this won't be becoming a real trend.

prove me wrong

I'll be honest and admit that I know little about parsing speed and DOM processing. But I have some common sense and when I apply it to the arguments given I can hardly imagine that we're really gaining something significant here, while at the same time we could be making much more important progress elsewhere.

But prove me wrong, I'm interested in seeing stats and figures on the effect of extra structural mark-up, superfluous semi-colons and quotation marks and unnecessary classes. Maybe then I can change my mind about things.

Comments

Jens Meiert

comment number
date
July 04, 2008 15:16

Niels, appreciate your thoughts and feedback. However, I kind of sense a misunderstanding here, and I felt free to reply in the original post [1].

[1] http://meiert.com/en/blog/20080616/validation-unimportant/#comment-70034

Niels Matthijs

comment number
date
July 05, 2008 12:45

Thanks for taking the time to read and reply to my remarks, I think it's best to keep the discussion going on your site from now on :)

Maniquí

comment number
date
July 08, 2008 20:54

Hi Niels, another great article. I agree with you, and have already commented on Meiert's article few weeks ago.

I don't believe in some extreme code optimizations: they usually make code less clear to be read, less flexible (as you already demonstrated in your html-vs-css series), less future-proof, and it teaches almost anything to newcomers.

Keep good stuff coming!

Dennis

comment number
date
July 09, 2008 00:06

It is possible to shave off certain elements and still have compliant markup in html and css. I don't believe taking out the trailing semi-colon is a good thing either. But for speed, taking out white space that's not really needed will make significant speed improvements for file size, and rendering speed. As for rendering speed, think of it like this. When the browser is reading the markup, it has to check for spaces in the tags, if it encounters a space, it has to skip the space, if the space isn't there, then it doesn't have to skip and just process the next tag element thus saving some speed. It skip spaces it has to execute code to skip the space, then continue on. The same can be done for server side processing as well. Take php and mysql as an example. You can save file size by referencing sql table cells as numbers ($row[username] as $row[0]) rather than by the column name, php can access that data faster as it doesn't have to try work out what column "username" belongs to but rather can access the column by it's number, therefore no thinking just direct access. With css, I believe the best way to try shave code, is to be smart about making markup for html elements, and to map out what elements the whole site will use, and try to build the least amount as possible to allow doubling up. For eg. mixing class and id css in one element, just remember that the last will override what comes before it. I've used this technique many times, esp. for form elements, where the id and name need to be used and the elements need to be different lengths, but have the same look. I'll class the look, and set id css for the lengths, using the form elements id, also allows javascript DOM integration for things like autocomplete ajax scripts. Just my 5 cents.....

Dennis

comment number
date
July 09, 2008 00:14

On Meiert's article, it's strange to note that he talks about shaving off things like the semi-colon for speed, but if you take a look at the source code, he's left all the tabs there, tabs also take up space, and processing time.

If you check out www.qcgo.com.au, and check out the source, you will notice that's it's all compressed down to single lines for each page. I will admit, that site isn't compliant (bad client, I gave up caring about the compliancy), which was done for speed compromises.

John Faulds

comment number
date
July 09, 2008 04:40

but I fail to believe it will have any important impact on the user experience

Performance enhancing's not just about the end user though. For smaller sites, these sort of savings probably don't really add up to much, but on high traffic sites, a few bytes saved here and a few bytes saved there can add up to substantial reductions in bandwidth usage and server load.

Niels Matthijs

comment number
date
July 10, 2008 09:47

But for speed, taking out white space that's not really needed will make significant speed improvements for file size, and rendering speed.

I understand the logic behind this, I just fail to believe it has any significant impact on the user experience.

If anything, why not change the class names themselves. With 2 letter class names you could easily have 900+ options, mighy save you plenty of bytes (in html and css).

a few bytes saved here and a few bytes saved there can add up to substantial reductions in bandwidth usage and server load.

Good point there, although we never had any problems there before, and I'm not the purest of html and css coders. It's a good think to consider when that becomes a problem.

Rogier

comment number
date
September 04, 2008 09:13

I keep being amazed by people, who think it is viable in some cases to invalidate HTML.

We don't do it in css/xml/php, so why should we do it in HTML? Just because some guy made this error once and the browser adapted to it, while they where in the browser war?

* required fields

Leave your data
Leave a comment