Ask A Question

Notifications

You’re not receiving notifications from this thread.

Gravatar blocked in China, need a workaround

Trevor Owens asked in General

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
Reply

I like #4 personally :)

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

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.