Reputation: 6345
I have a webpage that is HTML 4 transitional and HTML 5 compliant. In the latest version of the browsers is there a performance gain (decrease in the time to load/render the page) if I code the page to use the HTML5 DTD (which means don't put a DTD) over the HTML 4 transitional DTD?
Upvotes: 0
Views: 934
Reputation: 119847
The DTD
is just there to tell the browser (and a validator) what type of HTML you use and how your tags are deemed "valid".
DTDs use a terse formal syntax that declares precisely which elements and references may appear where in the document of the particular type, and what the elements’ contents and attributes are.
A DOCTYPE
tells the browser what mode to use: strict or quirks mode which dictate how the browser should layout the page.
The HTML layout engines in modern web browsers perform DOCTYPE "sniffing" or "switching", wherein the DOCTYPE in a document served as text/html determines a layout mode, such as "quirks mode" or "standards mode".
HTML5 has the doctype <!DOCTYPE html>
- a DOCTYPE with no DTD.
don't confuse them, they are different things.
There is no performance gain to it as far as i know. However, using a DOCTYPE
makes a browser layout the page in a standards-compliant (and a more consistent, but not totally) way across browsers. This is a "handsomeness" benefit rather than speed.
Since web browsers are implemented with special-purpose HTML parsers, rather than general-purpose DTD-based parsers, they don't use DTDs and will never access them even if a URL is provided. The DOCTYPE is retained in HTML5 as a "mostly useless, but required" header only to trigger "standards mode" in common browsers.
Upvotes: 0
Reputation: 83348
HTML5 parsing is 5% - 20% faster on Gecko
https://hacks.mozilla.org/2010/05/firefox-4-the-html5-parser-inline-svg-speed-and-more/
Upvotes: 1
Reputation: 11
The HTML5 doctype is several characters smaller than previous iterations which means fewer bytes and a smaller file size, which in theory would suggest that the HTML5 version has better performance.
However, I would suggest that if all you do is change the doctype, the performance gains will be minimal.
Upvotes: 1