0

I am developing a Ruby on Rails app.

Gravatar is blocked in China, where we have a ton of users. Which means if you pull from gravatar's 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
  • Do you mean that you have many users, that are not 'from' gravatar, but who just 'use'* gravatar for their profile image? – AntonTkachov Nov 18 '17 at 11:27
  • No, I mean for any users based in China, your app will not load and may even crash if you try to link to an image hosted on gravatar.com. – Fast Learner Nov 18 '17 at 12:36
  • 1
    You could try loading the image server-side, then base64 encode the data and render the image inline, that should get around any filters, something like: https://stackoverflow.com/questions/22717251/how-can-i-display-png-data-as-an-image-inside-in-the-browser – DivXZero Nov 18 '17 at 16:41

1 Answers1

0

There is a mirror here at https://cdn.v2ex.com/gravatar/5e801ed65b6f99fcad45fc7e61a5ffde

Also generally as a rule of thumb, the GFW is less forgiving for HTTPS traffic crossing, so if you use HTTP for gravatar.com, there could be some improvement

Qiong Wu
  • 1,504
  • 1
  • 15
  • 27