Firefox Counter
Firefox has been downloaded many times!
The original Firefox Counter met with rave reviews and a good ol' fashioned slashdotting. Not satisfied that I had wasted enough bandwidth, I decided to go a step further: host the counter feed on my server (rather than instructing people to mirror the feed on spreadfirefox). And that stroke of madness was the inspiration behind Firefox Counter 2.0.
Actually, the biggest problem with the original counter was that you had to wait at least a minute (until you received a second feed) before you could get an accurate download rate. The only way to solve this problem would be to cache several counts and send the download rate along with the feed. The only way to do this was to beg Asa to modify the official feed or to do it myself, and, well, Asa's a busy man.
The new counter includes a number of major improvements over the original. See the related article for more information.
Easy Integration: The Firefox Badge
If you're looking for a very simple way to place the live counter on your site, simply cut and paste the following code:
<iframe src="http://www.infocraft.com/projects/firefox_counter/frame.php" width="80px" height="15px" frameborder="0" scrolling="no">Get Firefox!</iframe>
An example and more information are available in the Live Firefox Badge article.
How to Use It
Feel free to drop a counter of your own onto your website. Here's how to do it:
- Download the PHP mirror script and place it on your webserver.
- Download the Javascript file and adjust the
counter_urlto point to mirror script you just uploaded. - Drop the Javascript on your server and place this code in the
<head>of the page(s) you want to include the counter (adjusting thesrcpath accordingly):<script src="ffcounter.js" type="text/javascript"></script> - Place the counter element in your webpage with the
id="ffcounter"attribute. For instance, I use:<span id="ffcounter">many</span> - If you can, please help me offset the bandwidth costs of hosting the counter feed with secure PayPal donation (no account needed, just a credit card). Donate as little or as much as you like, or not at all. I won't hold you to it, but I'd be very greatful for even as little as $5.00.
How It Works
The new counter works a bit differently than the old one. Previously, the counter would mirror the feed on spreadfirefox directly, and calculate a rate from different counts. The major problem with this was that you'd have to wait for a minute to elapse before you got the second count; and hence the first minute could only be an "estimated" rate.
Now, every time you load the page, it sends a request not to the original feed, but to a customized feed hosted here. This feed runs off of a database of previous counts. If you send a request to this feed and more than a minute has elapsed since the most recent update, it pulls the latest value from the official feed and sticks it into the database. If less than a minute has elapsed, it simply pulls from the database; this should keep the strain on the spreadfirefox servers to a minimum (one request per minute, regardless of how many people are using the live counter).
Upon request, the local feed sends you the most recent official count, plus a rate calculated from the last 10-minutes and the time that elapsed between the official count and your request. Your website uses Javascript to determine the current count (taking the delay into consideration) and begins incrementing the counter based on the given rate. Every minute, it re-syncs to get the latest official count and download rate. If your counter is off, it will speed up or slow down until it is realigned with the official count (NOTE: currently "slow down" means "stop until it's back in sync").
If you have any questions, comments, or suggestions, I'd love to hear them.
![Infocraft [Logo]](/images/logo.png)


