Ajax and RSS for Headlines

March 19th, 2005

A while back I experimented with using the XHR to pull links defined in an XML file on the server. I was able to make it work and create a Client-Side Include example. It is a very simple XML format and using JS/DOM it is easy to traverse the model and extract the data I needed.

Today I decided to parse a full RSS 2.0 feed and display those links dynamically. The result is the RSS Include example. I tested it in both Firefox 1 and MSIE 6. With a minor workaround here and there I was able to tweak it and add some useful features.

The primary problem I discovered is that I wanted to define properties on the XHR object. Normally you can do that on any Javascript object but the XHR in MSIE is really an ActiveX object and was not allowing me to do that. So I simply created an empty wrapper object and assigned the properties to that. In the code you will notice I simply process the request with an anonymous function which passes the reference to the wrapper object.

In this revision of the client-side include experiment I wanted to eliminate all global variables, especially the request object since it is asynchronous and I should be able to run more than one request at a time. Making it work with local variables helps avoid memory leaks, which I have read can get pretty nasty.

Once I had my sample Javascript working in a modular way I was able reuse a copy of it on the homepage of my website. I set it to display only up to 4 headlines. With more testing in MSIE and Firefox it works great, although I do not especially like the slight delay in displaying the links.

A website I managed for the Milwaukee Hurling Club is now also set up to use this script as well. It will allow the club organizers to use the blog software on the site to publish content. And as the club members become more savvy with RSS readers people may not even have to use the website to get the latest news. The adjustment I made on this site was to limit the homepage to only display 5 headlines max and only for the "Announcements" category. That will allow for other pages to display content for other categories, such as the Youth League and Camogie.

One feature which could be added to this script is to set a timer to refresh the headlines every 60 minutes or 4 hours. I do not see a lot of value for this particular use, but a Javascript aggregator could be used on a news site to provide a rich dashboard pop-up to keep headlines current. I could pop up that dashboard and leave it open all day. I like to use Bloglines.com but using this technique it is possible that I could create my own Bloglines.com where much of the processing is actually handled on the client. Perhaps that is the next experiment.

UPDATE: I had to roll this back a bit due to a problem I found with the Safari browser. I actually discovered this problem a while back and was hoping I could overcome it. See the next blog entry for an explanation.

Comments are closed.