Chovy’s Blog

Improving HTML: Worst Example I’ve Ever Seen

Fri, July 6, 2007 — Category: UI Design

We’ve all written code like this at one time or another. For many of us, its how we got our start.


1   <html>
...
192 <td>
193 <center>
194 <a href="javascript:;" onClick="MM_openBrWindow('118.htm','','width=500,height=333')"><img SRC="images/s118.jpg" BORDER=1 height=147 width=220></a>
195 <br>
196 <b><font face="Verdana, Arial, Helvetica, sans-serif"><font size=-1>WC118&nbsp;</font></font></b></center> </td>
197 </tr>

Format: The line #: The issue (the rule)

  1. Indentation missing
  2. Line 001: Doctype declaration (required)
  3. Line 192: tables used for layout (tabular data)
  4. Line 193: <center> tag used (layout)
  5. Line 194: useless “javascript:” link (sans-js)
  6. Line 194: “onClick” event handler (statically defined inline)
  7. Line 194: event function returns nothing (prevent default behaviour)
  8. Line 194: UPPERCASE tagname(s) and inconsistency (coding style)
  9. Line 195: <br> tag (layout)
  10. Line 196: <b> tag (deprecated, visual)
  11. Line 196: <font face=" (deprecated, visual)
  12. Line 197: </tr> tag (tabular data)

Re-written with improvements of poorly constructed markup and ideas.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <script type="text/javascript"><!-- // onload
      window.onload=function(){
        var functRef = function() { MM_openBrWindow(this.href,'','width=500,height=333'); return false; };
        document.getElementById('products').getElementsByTagName('a').onclick = functRef;
    // --> }
    </script>

<style type="text/css">
   #products { list-style-type: none; font-family: Verdana, Arial, Helvetica, sans-serif; }
   #products li { width: 200px; float: left; text-align: center; font-weight: bold; }
   #products img { border: none; }
</style>

</head>
<body>
...
<ul id="products">
    <li><a href="118.htm"><img src="images/s118.jpg" alt="Product ID: 118" /></a><br /><a href="118.htm">WC118</a></li>
    <li><a href="119.htm"><img src="images/s119.jpg" alt="Product ID: 119" /></a><br /><a href="119.htm">WC119</a></li>
</ul>
...
</body>
</html>

Presentation / Design

Redesigns will be much easier next time around, in theory only having to change the stylesheet file (I defined it local in above, but typically that would be referenced inside a file).

Behavior

Javascript is no longer a requirement for the site to work (this will become more of an issue as the XSS vulnerability word gets out, especially for sites that contain sensitive data).

Structure

Although clearly more markup (about double), we gained a few advantages by removing all the design and behavior attributes and tags. They tend to clutter up the markup, hurting readability. On larger pages and sites with heavy traffic, less data will be sent back by the server once the stylesheet and javascript libraries have been cached — vastly improving the load time on subsequent requests.

  • Post Improving HTML: Worst Example I’ve Ever Seen to del.icio.us
  • Post Improving HTML: Worst Example I’ve Ever Seen to digg
  • Post Improving HTML: Worst Example I’ve Ever Seen to Furl
  • Add Improving HTML: Worst Example I’ve Ever Seen to YahooMyWeb
  • Simpify!
  • Post Improving HTML: Worst Example I’ve Ever Seen to shadows
  • Post Improving HTML: Worst Example I’ve Ever Seen to Spurl
  • Post Improving HTML: Worst Example I’ve Ever Seen to BuddyMarks
  • Submit Improving HTML: Worst Example I’ve Ever Seen to Slashdot

1 Comment »

Comment by anon

November 29, 2007 @ 11:23 am

‘fraid to break it to ya, but that’s all generated by Dreamweaver! Big give-away is the function MM_openBrWindow. “MM” tends to mean Macromedia. Which in itself is defunct cause of Adobe… but hey, we all start somewhere!

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

 
Keyword Advertisers:
SEO Directory SEO Links Free Link Directory Shopping Submission Directory Gardening Tips Political Forum Search Engine Optimization Search Engine Marketing Audio Video Directory SEO Forum Web Development Blog Organic SEO Wiki Web Development Consulting

Learn more about purchasing keyword text link ads on this site.