Gravatar is slow.
You use Gravatar on your site.
Your site is slow.
We hate slow site.
Caching is fast.
Cache Gravatars on your site.
Your site is fast!
script/plugin install http://code.macournoyer.com/svn/plugins/gravatar_cache
Or using piston:
piston import http://code.macournoyer.com/svn/plugins/gravatar_cache vendor/plugins/gravatar_cache
Place something like this in your Rakefile:
def gravatar_emails User.find(:all).collect(&:email) # Return the emails you wanna cache end
Now put everything in place for showtime:
You might wanna run this in a cron job, here’s mine:
0 */3 * * * cd /var/www/refactormycode/current && /usr/local/bin/rake gravatar:cache RAILS_ENV=production
Caches it every 3 hours.
Now in your view (or helper):
Page caching friendly
It should be optimized for really high traffic sites as there’s no hole in the caching process (there’s always a cached version and no chance that someone hits a semi-downloaded file). It is page caching friendly as the url to the image won’t change when it’s cached or not (always /images/gravatars/MD5_OR_YOUR_EMAIL.gif).
You might have guessed that using a different filename for each Gravatar won’t save you any bandwidth. Even if two images are the same, a different symlink will be created for each, causing a new request for each Gravatar (empty or not). I’d suggest not using this plugin if you’re concerned about bandwidth.