Torsten Curdt’s weblog

Perceived Performance

beforeWhile tuning your server for performance is a good thing it’s not the only thing you should look at. Lately my blog pages felt to be loading a bit slow. Looking at the Safari network timeline it’s obvious that the flickr badge is (at least sometimes) dog slow and prevents the page to build up. The perceived performance suffers. And this has nothing to do with my server at all.

As there really no need for the flickr badge to be up-to-date to the second. I am caching it locally now. A cron script gets a copy and writes it to disk.

$ cat /etc/cron.daily/flickr
curl -s --max-time 120 --connect-timeout 60 \
 'http://www.flickr.com/badge_code_v2.gne?count=3&display=latest&size=s&layout=h&source=user&user=88457640%40N00' \
 | grep -v "flickr_badge_beacon" \
 > /path/to/cache/location/flickr.html

Then then it gets included like this

<script type="text/javascript">
<?php readfile("/path/to/cache/location/flickr.html"); ?>

As a result the load time decreased from 6.3s down to 1.6s. That’s almost 4x faster. At least in the user’s perception. YSlow is also a great plugin for firefox that helps exactly with this kind of optimizations.

Would probably be a good idea to turn this into a wordpress plugin.

  • @Odi: indeed a good suggestion!
  • Odi
    careful with curl in cron jobs. Depending on which version you have, it may hang in a busy loop sometimes. Make sure to specifiy a timeout!
blog comments powered by Disqus