Why You Should Be Using Locally Hosted Gravatars

gravatar wordpress

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.

20 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?

  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. 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.

Leave a Comment

6 Shares
Tweet
Share
Share
Buffer