Replacing plugins with template code: Gravatars
Lately I’ve been trying to reduce the number of plugins I’ve got loading to speed up my WordPress a bit, especially those plugins that do “stuff” in my theme. I’ve been replacing these plugins with template code, and this is the easiest fix I had so far: I replaced a 40k gravatar plugin with one (!!) line of code which generates all the images:
<img class="gravatar" alt="gravatar" src="http://www.gravatar.com/avatar.php?gravatar_id=<?php echo md5($comment-/>comment_author_email); ?>&rating=R&size=80&default=http%3A%2F%2Fyoast.com%2Fimages%2Fgravatar.png"/>
The source URL there needs some explanation:
- the gravatar id is an MD5 hash comment author’s email address
- the rating can be G | PG | R | X
- the default is the URL to my default image, instead of the blue gravatar image
Now my gravatars plugin did some server-side caching, but since Automattic acquired Gravatar a while back, they’re now super fast, and all that caching can just slow your site down, because you can’t beat their performance anyway.