tags:

views:

308

answers:

4

Is there any relation between doctype of an HTML document and browser rendering speed?

If yes then which one is fastest?

+6  A: 

I don’t think that the document type has an influence on the rendering speed. But the structure and style of an HTML document will have.

A complex HTML document (huge DOM tree, many embedded objects) with a complex style (floats, positioning, margin, padding) will probably need multiple rendering runs. Additionally an invalid HTML code the browser will need to do some error handling for parsing and building the DOM tree (but that’s not the rendering).

Take the Gecko reflow for example that shows how Firefox’s rendering engine Gecko renders an HTML document (videos for mozilla.org, a Wikipedia page and google.co.jp).

Gumbo
Interesting videos. Watching them, I can't help feeling that parsing the CSS plays a bigger part in the rendering than the HTML. Of course the two can't be totally seperated.
edeverett
@edeverett: Not parsing but applying it.
Gumbo
hsivonen
A: 

Based upon nothing but my own experience, I would venture that any difference is purely negligible.

There are a couple of factors in doctype choice that MAY affect it:

  • A strict doctype could involve less parsing time (providing no errors, obviously).
  • XHTML may take longer to load due to mandatory closing tags on everything.

However, this is going to vary greatly based upon your rendering engine and how they process source code.

I'm yet to see a website that's so optimised that the only thing left to look at is the doctype. To improve page loading speed, I'd use a tool such as ySlow or Google Page Speed to indicate more obvious areas for improvement.

Simon Scarfe
Do you realise that browsers don't actually parse you nice well-formed tag soup as XML, unless you send it with the application/xhtml+xml MIME type?
Ms2ger
I didn't know that, thanks.
Simon Scarfe
A: 

Google is one of the fastest sites on the planet. They use the following doctype:

<!doctype html>

At Google, "every byte matters".

To be sure, Google does a ton other stuff first. When you're at their level, you need to think about the number of characters/bytes you send out. So if you're at the point where you think changing your doctype will help, use the above.

Michael Hessling
It wasn't my down-vote, but that Google doctype is likely more concerned with bandwith than rendering speed. The google homepage is a tiny document, whereas HTML rendering speed differences are only likely to be noticable on large documents. For what it's worth, Google Reader uses HTML 40.1 Strict and GMail (non js version) doesn't use anything. But, yes, in general I don't think any doctype will make a difference.
edeverett
A: 

I've never heard about a rendering speed difference in the real world. It is similarly often suggested that XHTML will render faster. The idea being that with a well formed document the browser doesn't have to handle errors, but the browser doesn't know it's well formed until it's rendered it...

There are plenty of pages with Strict XHTML Doctypes that don't validate.

All the other factors involved are likely much more important - apart from download speed, the way you use CSS selectors can certainly have an affect for instance.

edeverett
Parsing is just the process of transforming the code into an internal representation (e.g. the DOM); thereby the syntax needs to be checked and syntax errors (missing tags, quotes, etc.) are recognized by the parser. But rendering is just the process of getting that internal representation onto the screen.
Gumbo