Brad’s Musings

A Smörgåsbord of gray gooey stuff from my brain 
« Back to blog

Pragmatic W3C Standards

I've watched countless debates on whether or not it matters if a web page validates against the W3C spec and heard plenty of weak justifications ranging from "Its just the right thing to do" to "it shows you're not sloppy". That kind of reasoning is on par with arguments heard during political and religious debates. Fortunately I've formulated something more objective:

Javascript Development
Building DOM-heavy javascript applications on top of a broken DOM is like building a 50-story condo on top of an old landfill with milk crates for the foundation. How can you develop and test javascript if the DOM is a heap of garbage? You can't, and if you try, you're going to run into some really quirky bugs. When a javascript-heavy web page validates successfully against W3C standards, it's one less thing that could go wrong.

Cross-browser testing
There is a huge difference between cross-browser testing and cross-browser compatibility. Compatibility asserts that all browsers implement the W3C spec and render pages consistently. The notion of browsers perfectly implementing the W3C spec to the "T" and rendering web pages consistently is a fantasy world, not unlike Candyland.

Cross-browser testing is the arduous act of viewing a web page through a jumble of different web browsers; if the DOM is not up to spec, you're introducing the "if the DOM is invalid, how will each browser compensate for its screw-ups?" variable into the mix. This is where web browsers enter a lawless world without any guidance, unless somebody could point me to the "Invalid HTML 4.01" spec.

A few weeks ago on Poll Everywhere, we had a single quote missing from a Rails helper that was causing some serious rendering issues in IE7. When I ran the page through the W3C validator, 63 error messages clued me into the line where the quote mark was missing and I was able to quickly fix the bug. After I added the quote, the page validated and the bug was fixed in IE7.

Regression against new Browsers
The second wave of browser wars between Google, Safari, Mozilla, FireFox, and Microsoft is a double-edged sword which will ultimately result in much better web browsers for all of us. The downside is that every 6 months it seems like there are more browsers that get added to the "supported browsers" list. Fortunately the newer browsers are embracing standards more and are getting closer to the golden standard of consistent rendering. If a web page is up to spec, there are less chances of it breaking when the newest version of your favorite browser is released.

---

I'm convinced that running web pages through the W3C validator saves hours of tracking down tiny bugs that propagate from an invalid DOM. For those of you running on top of a rails stack, check out the W3C validation gem and integrate it into your automated test suites (caution: this gem calls W3C over the wire and will slow down your test suite). Also, be sure to checkout HAML; it makes creating valid mark-up an afterthought.

What are some other objective reasons you can think of for validating the DOM?

Loading mentions Retweet

Comments (5)

Apr 12, 2009
cgranade said...
For me, validation is about playing nice with the community. If no one validates, then open standards don't mean any thing, and so we're stuck with a proprietary web.
Apr 13, 2009
unirgy said...
Exactly. You never know how the browser will behave if you add 'target' attribute to an anchor, or hidden input as a direct child of a form tag...
Apr 13, 2009
David Mosher said...
You hit the nail on the head. I've been making the effort to validate and it's saved me so much trouble :)
Apr 13, 2009
Hatem Nassrat said...
Where do we draw he line though, what about checking code through JsLint, or other bug finders for other languages. I agree with all that is said, and I think we should use these code checker tools to help us, rather than constantly complaining about them.
Apr 13, 2009
Brad Gessler said...
Safari 4 displays warnings in the console about screwed up markup. Maybe we draw the line at a code checker that makes sure the tags are closed, characters are escaped, and quotes are in the right spot? Its not really following a standard per se, but it does catch a lot of bugs that could cause headaches. Also, this test could be automated and run locally.

Leave a comment...

 
To leave a comment on this posterous, please login by clicking one of the following.
Posterous-login     twitter