Jump to main navigation, main content

Archived entry | Matt Wilcox .net

Goodbye DOCTYPE switching, hello META targeting

DOCTYPE switching is going to die, replaced by a more flexible and stable alternative. To me the new method makes perfect sense, but there seem to be waves of indignant objection rolling around over the topic at the moment. Me? I think this is the best thing to happen to web standards, ever. Allow me to elaborate on why this is bigger even than the whole revolution efforts of recent years. First, a little background:

What’s going to replace DOCTYPE switching

Beyond DOCTYPE: Web Standards, Forward Compatibility, and IE8 discusses the new method of telling browsers what rendering engine to use on a particular page. Right now, we have two choices - use ‘quirks mode’ which is the rendering behaviour and box model of IE5.5 and earlier, or use Web Standards mode. We do this by including a valid DOCTYPE in our HTML. It’s a switch that tells the browser how to interpret the HTML and CSS content. But, as Eric Meyer spotted too, this is an unsustainable method of controlling what browsers do with the code we give them. That’s because there isn’t one version of ‘Web Standards’ mode, it invariably has limited support, or a few bugs, in each version of a browser. IE6’s ‘Web Standards’ mode was very limited, and very broken. IE7’s was far less limited and not so broken. Which meant that when we told each browser to use ‘Web Standards’ mode by supplying a valid DOCTYPE they both did - IE6 getting it wrong, IE7 getting it (mostly) right. The result was a mess because site’s that rendered properly in IE6’s ‘Web Standards’ mode broke in IE7’s ‘Web Standards’ mode (correctly, however inconveniently).

DOCTYPE switching simply can’t handle multiple ‘Web Standards’ modes, and because each browser engine, and each version of a browser, has it’s own bugs and or limited feature set within it’s own “web standards” mode - you can’t treat it as a level playing field. It becomes a mess.

So the new method is brilliant - a simple meta tag that states what version of which browser the site has been tested in. The idea being that IE8 (and with any luck all newer browsers from all vendors) will look at that and use the render engine that is known to work. So, when IE8 comes out there won’t be any of the problems we saw when IE7 came out - because IE8 will see the meta tag and use the IE7 render engine to display the page.

Why the ruckus?

The default behaviour of the new model, and the impact on JavaScript libraries. Both are problems to us Standards Aware developers, but I have no doubt that the latter can be fixed and the former is a necessary sacrifice for us to endure, and also an amazingly powerful tool to force the uptake of Web Standards; where all other efforts have produced merely a tiny (but passionate) minority of educated developers, still wading in a sea if ignorant ones. This is how new browsers like IE8 will handle pages without a tag:

If a page doesn’t have any version-targting information, then the DOCTYPE will be used as a proxy for version targeting. For example, all the HTML4 and XHTML1 DOCTYPEs will be targeted to IE7 by default. In the future, HTML5 DOCTYPEs might by default be targeted to IE9 or IE10, depending on how things shake out.

Eric Meyer, A List Apart: From Switches To Targets.

Makes sense, it ensures that pages without a meta-tag (which is every page on the web right now) are rendered in a mode most likely to display and behave correctly. This is no worse than if we had only the regular DOCTYPE method. Concerns that in future pages authored for modern browsers will render wrongly because of a missing meta-tag are incorrectly placed. Just as authoring environments now include valid DOCTYPES, in future they will include realistic meta-tags. Thus mitigating the problem. And were anyone to develop a web page in future-land via notepad for example, and not have the META tag, well when they are testing their page the browser will be rendering in a fall-back DOCTYPE induced mode anyway. Basically, it’s impossible to produce a visually broken page because of ignorance, even if you could still produce a tag-soup mess.

Why the new system is a driving force for learning standards

The default behaviour does remove the option of using ‘progressive enhancement’ from us. A method whereby authors write little bits of CSS that are not supported in current browsers, but will be in more modern ones. It means that when the new browsers show up there will be a few minor display flourishes for them to see. Well, that won’t happen any-more unless you specify ‘edge’ in the META tag, because the default treatment is to render as IE7 not IE8. Well so what?

You get to keep progressive enhancement by turning the tag to ‘edge’. So the people that use the technique (used only by standards aware and smart developers, by definition) get to keep the current behaviour of ‘give me the new shiny as soon as you can’. Those that don’t know about the new tag system are not the people who are coding in a ‘progressive enhancement’ style anyway, so there is absolutely no loss there.

Further, I think the new default of ’stay as IE7 when no meta tag found’ will enhance the uptake of web standards. Because every ignorant developer on earth is now going to be permanently stuck with IE7 rendering and behaviour. They will never get to use any of the new-shiny of IE8 and above if they don’t know to include that meta tag. They won’t know to include that meta tag until they go away and learn about web standards.

If I could, I’d have every browser on earth fall back to the current DOCTYPE switcher mode if any part of the page did not validate. That’d stop ignorant developers simply slinging in the meta tag and carrying on producing tag-soup. It would force valid pages if you want to use CSS3 or the new ECMAScript. And all the while leaving the rest of the web totally unbroken.

In my eyes, the new switcher is brilliant, but doesn’t go far enough!

Comments

skip to comment form
  1. Matt Wilcox posted 7 days, 17hrs, 35mins after the entry and said:

    John Resig, the man behind jQuery, has an insightful counter-point at his blog. Well worth a read:
    http://ejohn.org/blog/meta-madness/

    As an aside, it's looking very much like the switch will not turn out as I had hoped. Validated code doesn't seem to be required, and because of that, the entire thing is going to be a complete mess. There is nothing stopping this from becoming the new DOCTYPE switch in a couple of years. The meta-tag alone doesn't fix the problem Microsoft claim to address, but postpones it for a while.

  2. Hoopskier posted 8 days, 13hrs, 0mins after the entry and said:

    I'm not sure how well requiring validated code would work in practice. First, there is progressive download: while I'm waiting for the page to finish downloading I want to start the layout and rendering process, even though I don't know if there's a validation error coming down the wire later, or if the connection will be dropped and the page left half-downloaded. What should the browser do in this case, replace the already-rendered partial page with an error page?

    Similar thing for things such as innerHTML. What if you try to insert markup that would make the page invalid HTML? IE, surprisingly, catches some of these and innerHTML will throw a script error, instead of doing fixup which other browsers choose to do. What is the right thing, throwing a script error, doing fixup, or inserting it and then going to an error page?

    Good points, well made. I thought someone else must have thought of the idea and rejected it, but couldn’t find anything. As a quick question though - Firefox will validate XHTML sent with the correct MIME type (that’s why this site breaks if I mess up an encoded character or forget to close a tag) - so surely there are solutions to the problems you mention?

  3. Matt Wilcox posted 10 days, 21hrs, 37mins after the entry and said:

    Interesting comment on Adactio by Chris Wilson (one of the IE lead programmers):

    "…the problem is that we can’t tell the difference between your content (valid HTML with a correct HTML 4.01 DOCTYPE) and that of someone who hacked up their own content to work with IE6/7…"
    http://adactio.com/journal/1402/#comment246

    - Sure you can Chris, you outlined exactly the difference in your own comment: parse the page and check that it's valid. If it's valid, chances are exceptional that it's been designed to work to standards. If it's bust, then stick with the IE7 engine.

  4. Jake posted 343 days, 6hrs, 53mins after the entry and said:

    I have question for you that know a lot about HTML. Im new and have a question.

    Is it ok to place meta tags above the "Doctype html" line?

    Does this even matter? Will the robots read it the same?

From the archives

Other enteries filed under:

Web Development

Site information

Built with valid XHTML and CSS, designed with web standards and accessibility in mind. Best viewed in a modern browser [Firefox, Safari, Opera]

This domain and all content is a copy of my old website, for historical purposes only.