Technology - RSS Feeds

RSS feeds, or really simple syndication, have been around for longer than people realize, and have become a bigger hit with the explosion of the blogosphere and portal sites like iGoogle. Being able to create your own RSS feeds is a good thing to know, since they allow you to share updates and information from your website or other source that people can access via many different RSS feed readers.

There are also many uses of RSS feeds that you can take advantage of from a web development standpoint rather than just viewing them in your favorite reader. You can access RSS feeds programmatically using both server-side and client-side technologies and use them to create dynamic and even customizable content that your site's visitors will enjoy.

Examples of Creating Feeds

Aside from the automatically created feeds like you get with your favorite blogging sites, here's an example of a set of RSS feeds I created for the Nighthawks Hockey Online website at http://www.nighthawkshockey.com/rss.php.

Essentially, creating an RSS feed involves generating an XML document in a standard format. This format has many features for listing articles, authors, descriptions, dates and times, etc. While you can choose to create a static rss file with a .xml extension at regular intervals, the feeds I created for this site are actually PHP scripts that gerenate the feed real-time when it's requested.

What's interesting about these feeds, and what makes the useful to the site's visitors, is that they cover different and diverse aspects of the site, allowing the user to pick and choose what interests them. There is a standard Today's Posts that shows any recent activity in the site's forum. There is the also a Nighthawks News feed that shows articles from another part of the site, and things like game results and league standings as well. As you can see, these pull from different data sources and actually different types of data, which adds the variety to fit the needs of different users.

Examples of using feeds

As mentioned earlier, you can also use, or consume, feeds on your own websites that are hosted by other sites to help provide information to your users. On the Ka'anapali Dreamin' site, I have a page called Daily Content that uses RSS feeds hosted by The Hawaii Directory to add something new to the site on a daily basis. In this case, there are 3 different feeds, such as the Hawaiian word of the day, that I consume using AJAX functionality to display on the page as it's loading.

Interesting enough, there's more than one way to use those RSS feeds in your sites. The example above uses client-side scripting (JavaScript) to add content to the page after it loads so that the user gets the benefit of the page loading quickly and not waiting for the server itself to read those feeds and output the HTML necessary to display. The downsides, depending on how important they are to you, is that there are security concerns and restrictions in some browsers (which is always a good thing) and the lack of support for search engines because the HTML output for these feeds are loaded after the page is downloaded.

The second option for processing for using RSS feeds for your site is to process them on the server-side, which bypasses those two notes about security and search engines. It does introduce its own set of compromises, however, but I'll get to that in a moment. Here's an example of how I've processed RSS feeds using server-side functionality. It's the Today's Photos page at Ka'anapali Dreamin'. For this, my preference is to have the HTML present on this page to be accessible to search engines. Since the feed for this page only changes once a day, I cache it on the server side (in a database table) to ensure that I'm not downloading the same exact file everytime when I don't need to.

So the caching step above is how I overcome any delay in downloading the RSS feed and waiting for that step to complete. The other challange is using server-side technology for parsing and navigating the XML in an RSS feed. On the client-side, JavaScript makes it very easy and standard for using XML data. On the server-side, you have a large array of choices (Perl, Python, PHP, .NET, etc.) but could also be limited to what your web host has installs and suports.

For me, the server-side scripting I use for my personal sites is PHP. There are many publically available and robust XML libraries for PHP, with the gotcha that they're only available for the 5.0 version. My host only runs version 4.x. Luckily, I found a very easy to implement parser, the DOMIT XML Parser that I was able to install on my own.

Additional Resources

Additoinal resources and links will be added here.