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?
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.