StackExchange Flair

Submitted by Robert MacLean on Tue, 10/12/2010 - 15:16

For a while the flair on my site has included my stats from StackOverflow, ServerFault and SuperUser. In my article on it, I mentioned I used the iFrame but I stopped that a few months ago and switched to getting the JSON data for my accounts directly and parsing that. I did this as it was order of magnitudes faster than loading via the iFrame.

For those who attended my DevDays talks, they would recognise that code as it is the same as I used in my demos.

Then recently an email arrived:


Damn, my jQuery magic was about to end so what could I do but change? When I started looking at the new flair I noted that StackOverflow wanted me to hotlink the image, i.e. have my visitors get it from their server, but the performance for pulling the image was still poor compared to my own website (or so the Firebug tool says). So what could I do to improve this? 

What I did was to use wget, which is a Linux tool (I’m hosted on a Linux box) for downloading files, and put that in a schedule to once a day download my StackExchange flair and store it on my website, which means it gets served faster. As my numbers won’t change heavily day to day, (I’m not Skeet) once a day is enough balance between keeping it fresh and making it cachable.

The only downside is that my flair uage stats on StackExchange will likely drop, but I don’t really care about that.

The wget command is:

wget –O <path>/files/stackexchange.png