12 Apr 2009

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?