Skip to main content

Gravatar blocked in China, need a workaround

General • Asked by Trevor Owens

Gravatar is blocked in China where we have a ton of users. Which means if you pull gravatar from their site in your app, your website will crash/not load for anyone based in China.

So I have two options:

  1. Upload all gravatars to s3 with workers and serve them ourselves
  2. Figure out a workaround

Workaround #1 is to use a CDN like cloudflare that I can use to serve Gravatars. It would be great if something like this existed that was plug and play, it would also improve performance.

Workaround #2 is to pull from the Chinese gravatar mirror for anyone who is within China based on their IP address.

Workaround #3 is to cache the images with Gravatar Ultimate gem which uses ActiveSupport::Cache::SynchronizedMemoryStore.new (https://github.com/sinisterchipmunk/gravatar). I'm not sure if this is scalable for tens of thousands of daily users.

Workaround #4 is to detect the failure from Gravatar somehow in the browser and if it fails to display the default (non-image based) avatar. Would be great if it did this for all avatars after the first try or remembered and remembered on subsequent attempts.

Perhaps the fourth is the easiest/most robust, but I'm not sure how to do it. For gravatars, I've always used this simple helper method:

def gravatar_url(user)
    gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
    "http://gravatar.com/avatar/#{gravatar_id}.png?d=identicon&s=150"
end

I like #4 personally :)

What does it look like when the image does not load? Does it show up as a 404?


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.