We recently launched the Instant Website Speed Check and used the Yahoo User Interface (YUI) libraries extensively to build the client. Specifically, we used the following components from the YUI library…

  • YUI DataTable - Used to display the latency test results.
  • YUI Connection Manager - Used to execute the AJAX calls to the server to start testing and to poll for test results
  • YUI Reset/Fonts/Base/Grids CSS - Used to provide a foundation to layout the page and elements on the page consistently across browsers.

This is my second project using YUI and I’m still climbing the learning curve. This blog entry reflects the point of view of someone still learning YUI versus an expert explaning the best way to use YUI.

The YUI DataTable is a relatively complex control with lots of options. While I would use the DataTable again on a project, I often find it frustrating finding out how to accomplish simple things. For example, I had trouble figuring out how to update a cell in the table — I ended up writing the following javascript method to update a table cell…

// Updates a cell in a YUI DataTable
//   record - The instance of YAHOO.util.Record that should be updated
//   fieldName - The key name of a column in the YUI DataTable
//   value - The new value for the cell
function updateCellValue(record, fieldName, value) {
  var column = _dataTable.getColumn(fieldName);
  var cellRef = {record:record, column:column};
  var cell = _dataTable.getTdEl(cellRef);
  _dataTable.getRecordSet().updateRecordValue(record, fieldName, value);
  _dataTable.formatCell(cell.firstChild, record, column);
}

I’m guessing I jumped through some unnecessary hoops to update a cell but I really couldn’t find a better way after 30 minutes of reviewing the YUI API Documentation. Overall, I found the YUI documentation and examples to be excellent although I struggled to find a better way to update a cell in this case.

The YUI Connection Manager was quite straightforward and easy enough to implement. With the Connection Manager, you simply make a call to YAHOO.util.Connect.asyncRequest passing in GET/POST, passing in the URL, passing in a callback object with success and failure handlers, and passing in the post data. Here is the javascript method that initiates the testing…

function createInstantDataSourceSet() {
  var url = '/speed-check/index.jsp'
  var callback = {
    success: function(o) {
      var instantDataSourceSetId = o.responseText.trim();
      pollForInstantMonitorTests(instantDataSourceSetId);
    },
    failure: function(o) {
      alert('Failed: ' + o.statusText);
    }

  };
  var instantDataSourcesJson = buildInstantDataSourcesJson();
  var postData = 'step=create-instant-data-source-set';
  postData += '&instantDataSources=' + escape(instantDataSourcesJson);
  YAHOO.util.Connect.asyncRequest('POST', url, callback, postData);
}

The Connection Manager was easy enough to understand and implement — no problems there.

Regarding using the Reset/Fonts/Base/Grids CSS, this worked out extremely well as it seemed to greatly reduce the work required to tweak the UI to look consistent across the major browsers (Firefox, IE, Safari, and Opera). The client was designed in Firefox initially and then tested under IE, Safari, and Opera — there was probably just 15 minutes spent tweaking the input bar area to layout consistently across all the browsers.

Overall, we plan to continue to use YUI on future projects.

Bookmark at:
StumbleUpon | Digg | Del.icio.us | Dzone | Newsvine | Spurl | Simpy | Furl | Reddit | Yahoo! MyWeb
10 Responses to “Impressions of Using YUI to Build a Website Speed Check Client”
  1. [...] brand new article from trendics.com about how they used YUI library to build [...]

  2. Love the new speed measurement site! Congrats on getting that launched and for sharing your thoughts on DataTable.

    I wanted to let you know that we’ve added combo handling to yui.yahooapis.com, so you can reduce your HTTP count on that page pretty dramatically:

    That will take out five http connections, which is a nice savings.

    Continued good luck with the project!

    Regards,
    Eric

  3. Awesome, Eric. I’ve implemented this and I’ve crossed one item off my YUI wishlist. :)

  4. Came across your blog while searching on a similar issue. Here is the solution I have.
    If you have the YAHOO.widget.Record (the first arg in your function), then a simple record.setData(key,value) should work to set the data and format the cell (it does for me).

    The only trick with it, is if you have a parser setup in your datasource, then you must do the parsing yourself. E.g:

    oRecord.setData("subscribe_ts",YAHOO.util.DataSource.parseDate(rsp.subscribe_ts));

  5. I would edit my reply if I could, but I realize I also refreshView on the dataTable, which is what does the reformatting of the cell.

  6. Thanks for the tip, GerryL.

  7. I couldn’t understand some parts of this article s Blog » Impressions of Using YUI to Build a Website Speed Check Client, but I guess I just need to check some more resources regarding this, because it sounds interesting.

  8. WOW!, Excellent post, I’m really glad I found your blog. I just love your post. Keep up the good work. Cheers!

  9. cool

Leave a Reply