4.8. Use Case for Building: The Firefox Counter
After the Firefox 1.0 release, the Mozilla project added a number of grass-root marketing approaches to their marketing effort. One of these was asking people to add a counter to their Web sites showing the number of Firefox downloads. This data was provided by a Really Simple Syndication (RSS) feed; some implementations read this data at the server and then rendered it during the normal page generation process. Building on this basic approach, Matthew Levine built a small AJAX odometer-style counter that updates continuously. An example of this is shown in Figure 4-4. In this figure, an AJAX request is made on a regular interval, with rate information being used between updates to continually update the displayed count.
Figure 4-4. Version 2.0 of the Firefox counter
This is a very basic use case for AJAX. To implement the counter, you need to do a GET request to a single page and then grab three data points from an XML file. Because you're only going to be making a single type of request, you don't need the full-blown AJAX support that most libraries provide. It's also a small feature you are adding, so lots of error handling or other status feedback isn't really useful. The concept behind the counter is that it's an informative marketing technique, and while it's more active than a mere image, it's not the major draw of any page it's on. To accomplish this design goal, all you need is an implementation that updates in a smooth fashion or that dies silently when there are problems.
In this case, building custom AJAX code was beneficial because ease of deployment and small size were more useful than the quick development time that a pre-built library might have offered. The simplicity of the AJAX code also removed much of the need for a library because in this basic case, we needed to focus on only one type of request. If we were combining the counter onto a site already using AJAX, we might want to swap out the communication component to increase consistency, but because a counter by itself needs no other features, it makes little sense to bring along other features that will never be used.