Don’t call me DOM

29 June 2006

Mobile Web Best Practices checker

As announced in the WWW2006 conference and as part of the Press Release accompanying the publication of the Mobile Web Best Practices as a Candidate Recommendation, work has started on the development of an open-source Best Practices checker.

It is still at alpha release stage and hasn’t been properly reviewed by the Mobile Web Best Practices Working Group; meanwhile, developing it has been a lot of fun!

First, for once, I was able to code in Python; even though my skills in Python are still rough and my ratio PHP/Python line codes must be around 1/40, I would give all my PHP code for keeping Python code only. For mostly historical and logistical reasons, most of my day to day coding has been (and likely will continue to be) made in PHP, but PHP really looks like an ugly pig compared to the lightness and flexibility of Python. Really.

Secundly, I was able to work with unit-tests from the very beginning; I’m usually doing a lot of database-bound applications, which I find really cumbersome to unit-test; in this case, given that the code targets HTTP delivered content, designing and setting up unit tests was extremely easy, and proved similarly valuable: it’s hard to over-estimate the confidence you get in your code when you know it passes a series of well-defined tests.

Thirdly, while some of the code is really mobile-specific, a lot of it could be used a basis for a more general Web Best practices checker: it can make interesting remarks on form controls (e.g., check whether each control has a corresponding label), on images and their dimensions (e.g., whether the dimensions of the images are defined in the markup and whether they match the dimensions of the image itself), on auto-refreshing and markup-redirect pages, on the proper usage of HTML headings, on the usage of tables layout, etc. Codifying some of these well-known Web design issues in actual tests and code was sometimes challenging, but mostly very rewarding.

Finally, I got to use a nice set of very Webby technologies:

  • first of all, the checker uses thoroughly caching for its HTTP requests, thanks to httplib2 which does most of the dirty work;
  • given that the checker also does some markup validation, it relies on xmlproc catalog’s handling capabilities to skip any HTTP activity for known DTDs;
  • a great chunk of the analysis made rely on SAX parsing; it was my first opportunity to use SAX in some real coding, and I have to say I found it quite pleasant to use
  • some of the devil-lies-in-the-details tests for encoding and MIME-types needed careful comparison between the various specifications involved (HTML, HTTP, MIME-Types, CSS among others)
  • I got a fairly nice logic/presentation separation through the use of templates; for (potential) compatibility with the Markup Validator, I used a Python implementation of Perl’s HTML::Template language

There is still quite a lot of work to be done to make it more robust and more complete; in particular, I need to analyse CSS style sheets for testing some of the best practices: I was thrilled when I discovered cssutils – CSS Cascading Style Sheets library for Python, until I realized it doesn’t implement the most important CSS DOM interface I needed. I’m left with the option of either implementing it myself, or looking at using some other non-Python library (e.g. libcroco). I’m also hoping to use Mark Nottingham’s cacheability engine to implement the test for the Best Practice on caching, if I can get it to play well with the other modules.

But I’m already quite satisfied with all I learnt during this first phase, and the feedback I’ve been able to provide the Working Group based on this coding (which reminds me that I still have some rather thorny implementation feedback to send!).

The code is already available and there are some velleity of an installation document if anybody wants to play with it; if you want to contribute to the project, I very much welcome so; just drop me an email at <dom@w3.org> to get in touch!

2 Responses to “Mobile Web Best Practices checker”

  1. Jessica Says:

    I am creating my website at the moment around a web standards compliant website and now figure what the heck lets see if I can make it mobile compliant as well around what the w3 has offered up as guide lines.Should be interesting to see how hard or easy they are to follow, just wanted to congratulate everyone who took there time to share there thoughts on the Best Practices project, and for allowing the public to comment on what they thought was important for Best Practices.

  2. Dan Connolly Says:

    Nifty.

    I started browsing the code… lots of unit tests… yum.

    In page_title.py, I think using hasattr is overly dynamic:
    if hasattr(self,”_title”):
    That might not work well in psycho or Jython or the like.

    I see the docs on how to install, but I then what? How do you run it?

    I hope to put some time into this soonish. If you haven’t heard from
    me about it in a week or two, I’d appreciate a reminder.

Picture of Dominique Hazael-MassieuxDominique Hazaël-Massieux (dom@w3.org) is part of the World Wide Web Consortium (W3C) Staff; his interests cover a number of Web technologies, as well as the usage of open source software in a distributed work environment.