Why You Should Be Using Locally Hosted Gravatars

As many of you know I am a big fan of Disqus and using a click to load comments setup. However I also use native WordPress comments on my personal site: brianleejackson.com. I am a stickler when it comes to speed and noticed tons of HTTP requests loading out to gravatar.com. So I decided to come up with a better solution.

Using locally hosted gravatars decreased my site load time by over 2 seconds!

Site Using Default WordPress Gravatar Setup

By default with the native WordPress commenting system it pulls a gravatar image for each user’s comment based on their email address. If it can’t find one it uses the default image from gravatar’s server. What this ends up doing is creating a ton of HTTP requests for each image as well as unnecessary redirects. Below is an example from my brianleejackson.com site.

gravatar redirects

Here is a speed test with the default setup. Make a note of the # of requests, 141.

site speed default gravatars

You can see the ridiculous amount of components it is querying under the DNS lookups for both 1.gravatar.com and 0.gravatar.com domains.

dns lookups default gravatar

Site Using Locally Hosted Gravatars

So I decided to switch my site to use locally hosted gravatars to minimize all of the redirects and HTTP requests. This also means they would be loading the images from my CDN as well.  Here is a speed test after the configuration change.

site speed local gravatars

You can see simply by changing to locally hosted gravatar images I decreased by load time from 3.36s to 1.27s and decreased the total number of requests from 141 to 59 as well as the page size!

This wipes out the DNS requests to the gravatar domain completely.

How to Setup Locally Hosted Gravatars

Follow the steps below to setup locally hosted gravatars and shave some seconds off of your load times! Now remember this will disable showing other people’s gravatars. But how important is that to you? Is it worth slowing your site down?

Step 1

First we are going to install a free WordPress plugin called WP User Avatar.

Step 2

Once you have the plugin installed in the WordPress dashboard hover over Avatars and click into “Settings.”

avatars settings

 Step 3

In the settings menu click on “Disable Gravatar and use only local avatars.” Then choose a default avatar.

wp user avatar settings

I am not a big fan of the default one from the plugin so I actually uploaded the following image. Feel free to save it from my site and upload it on yours.

gravatar

Step 4

I then go into my WordPress profile and choose a custom avatar for my author profile so it will show up when I comment and reply on my blog.

my personal gravatar

And that’s it! Your site should now run without all those additional queries to gravatar’s servers. And if you have a CDN implemented they will also load quicker!

Alternative Solution

Pascal from SpinPress also suggested a great alternative WordPress plugin: FV Gravatar Cache

This plugin solves the gravatar problem by problem by:

  • caching gravatars with WordPress cron job
  • caching gravatars on comment submission
  • maintaining a single copy of the default gravatar instead of downloading it again and again for all the email addresses with no gravatar associtated

Both of the above solutions are great ways to solve this problem. As always feel free to leave your comments below.

Get More Stuff Like This

Marketing, WordPress, Blogging Tips, SEO and Reviews, once a week.

Thank you for subscribing.

Something went wrong.

21 thoughts on “Why You Should Be Using Locally Hosted Gravatars”

  1. Does it work well for new commenters? Does it do periodic checks to update the avatars in case they’re changed? From what I’ve seen so far, it seems more suited to a regular user base – would that be a fair comment?

    • No, this plugin only allows you to upload custom avatars for users. It shows the mystery man (blank portrait) for all visitors who aren’t logged in. So it’s not *that* helpful.

      There are better plugins that cache Gravatars locally, e.g. https://wordpress.org/plugins/fv-gravatar-cache/

      They work as follows:

      1. Rewrite avatar urls to point to a directory on your server
      2. If the image (e.g. {hash}.png) exists, load it directly.
      3. If it doesn’t, request the picture from Gravatar and save it for a couple of weeks
      4. Profit.

      IMHO you should integrate that directly on the server level to make sure you don’t load WordPress for every avatar request.

        • Thanks Tim for your comment!

          Like I said in my post above… it will show the mystery man for every user. So yes it does work for non-users. I simply don’t want that extra load time.

      • That looks like a great plugin Pascal… I will have to give that a try. It seems pretty buggy, but I will give it a try. Do you use this on your site already?

        • Nah, I’m not using it on a site yet. How buggy is it? Maybe we can write a patch :)

          I’m really thinking about doing this directly with nginx & a small PHP script that fetches avatars. Such an approach would improve avatar load time even further and doesn’t rely on cronjobs or WordPress (except for filtering the avatar url). Just haven’t found time yet.

      • I have edited my post and added your alternative solution. Gave you a shout-out. Thanks again for taking the time to comment!

  2. Nice post and plugin. I’ve noticed that a lot of requests were made to Gravatar, thus slowing down the websites. It’s also worth mentioning that you can do some custom coding to load your Gravatar (if you are the admin that is replying to lots of comments) locally.

  3. Brian, great! thanks for this, another new plugin I have found that actually works best for simplicity for deferring and minifying java and css is autoptimize… otherwise I would use W3 total cache and manually load each script. but this one works with a few clicks, truly amazed.

  4. Yes. Locally hosted Gravatar images can be optimized by image optimizer like optimus or something else. So this is best idea i think.

    If you upload an optimized image in wordpress gravatar profile, That sometimes not works. I tested with Google page speed insights many times before. It said that image should be optimized.

  5. Hi ,
    I want to host an internal Gravatar which every user needs to be used within our Organization.
    Any ideas or tool suggestions are welcome.
    T

  6. Had been debating the usefulness of Gravatars and how to shave off on loading time for my new blog. Finally found this blog, created a Gravatar and started local caching. It’s been a week so far and all’s good. Thanks for posting.

  7. Hi tɦere collеagues, hߋw is everything, and what you would like to sаy about this article, in mу view its really awesome in favor оf me.

Leave a Comment

shares