The structured markup dividend

Joe Gregorio

Marc Hedlund on the O'Reilly Radar points out the Behaviour JavaScript Library.

The idea behind this Javascript library is great -- it's similar to what I argued for in Why JSP Sucks So Hard. As I mentioned in my post on Ruby on Rails, I still find it grating when I see so much non-HTML code in an HTML page; and the CSS marker system seems like a great way to hook code and markup together. Cheers to the Behaviour folks.

I will note the irony that the original HTML quoted above has inline JavaScript in every anchor:


  <a onmousedown="return insertScript('http://oreillynet.com/pub/wlg/2423')"...

Anyway, I had no idea how cutting edge I was, maybe because it never crossed my mind to litter my HTML with JavaScript. In my Sparklines Generator there is only one line of JavaScript in the HTML:


  <body class='main' id="top" name="top" onload="setup();">

All of the onwhatever behaviours are hooked up on the fly in the setup() function. It wasn't a conscious decision to be cutting edge, but a practical one that followed from my decision to make the application as data table driven as possible.

Not only are we are seeing the benefits of clean structured markup in faster load times and more flexible designs, we are also getting the unexpected dividends of enabling new developments like microformats and now Unobstrusive JavaScript.

Further Reading:

Updated: Re-tagged this as 'unobstrusive javascript' to bring it into line with Simon Willison's work on the subject. Also added the further reading section. I may also need to go back and update my Sparklines markup since I used divs instead of fieldsets.

Tags:
Why are you using <body onload="setup()"> when you can also do it "on the fly"?
e.g. window.onload = setup; or window.onload = new Function("setup();"); or window.onload = function() { setup(); }; or even something with window.attachEvent/window.addEventListener.

Posted by Thomas Broyer on 2005-06-30

Thomas,
  Good point.

Posted by Joe on 2005-06-30

These are good ideas. My own markup is starting to feel like spaghetti, between the CSS, html, php, and javascript.  I really need to find time to refactor it.

Posted by James Ashley on 2005-07-05

comments powered by Disqus