Allow webmasters to redefine Gravatar URL to a mirror inside of Mainland China.

ShikiSuen

Well-known member
At present, Gravatar is hard-walled in Mainland China GFW Circle.
This tremendously brings down the speed of accessing every webpage of a Xenforo website (with Gravatar enabled) hosted outside this circle...
Plus, until all Gravatar loadings gets finished (or ended with an error), the Froala Editor simply DOESN'T load.
(TBO, I tested the access from Guangzhou and seeing that Chris Deeming's gravatar failed to be loaded after averagely 50 seconds, always.)

There are only two choices:
One is to completely disable Gravatar in the admin panel;
The other one is to use a self-built mirror of Gravatar to bypass the GFW block.

For instance that the W3TT (World Wide Testing Team, an NGO) provided their gravatar mirror, and we can see that Chris's avatar loads successfully:
https://gravatar.w3tt.com/avatar/6a47eeb728f63ec47960fdeffffe750a?s=96
6a47eeb728f63ec47960fdeffffe750a


There is a trust issue that not every mirror are always reliable, hence my thoughts:
Allowing site admins to decide which Gravatar mirror they can use by putting their trusted Gravatar mirror URL.
Meanwhile, if this value has not been set, then by default XenForo just throw a universal avatar icon to all visitors whose IP addresses are from Mainland China, saving dozens of seconds of webpage loading time.
 
Upvote 1

ShikiSuen

Well-known member
Meanwhile, until XF officially ships this experience improvement (if they are glad to), site visitors from Mainland China can simply modify their HOSTS file on their computers to put secure.gravatar.com to 127.0.0.9 which triggers an SSL error, letting their browsers immediately cut down the long-waiting connection between themselves and the Gravatar official server. Now they can enjoy the blazing-fast XenForo visiting experience.
 

ShikiSuen

Well-known member
I wonder whether this helps... Lemme note it here first.
Code:
document.body.innerHTML = document.body.innerHTML.replace(/https\:\/\/secure\.gravatar\.com/g, '{$xf.options.gravatarMirror}');
1620131108314.png
 

ShikiSuen

Well-known member
Update: I successfully injected the Javascript to the webpage.
However, it is not effective to those popups like "alerts" and "member tooltips", etc.
=======
Template: PAGE_CONTAINER
Modification key: Modify_Gravatar_Mirror
Search Type: Single Replacement
Find: </head>
Replace:
Code:
<script language="javascript">
    document.addEventListener("DOMContentLoaded", function(){
        document.body.innerHTML = document.body.innerHTML.replace(/https:\/\/secure\.gravatar\.com/g, '{$xf.options.gravatarMirror}');
    });
</script>
$0
Executive Order: 1
Automatically apply template modification: Checked.
=======
1620135746407.png
I need to find a way to hook it into every place right after every usage of "xf:avatar"
 
Last edited:

ShikiSuen

Well-known member
Won't need any template replacements, can just extend the XF\Entity\User::getAvatarUrl function and automatically hit all avatar places.
Looks like I need to find a PHP expert to deal with this by following your suggestion.
(I know nothing about PHP programming at this moment.)

An alternative workaround is to ask end users to install this browser addon...
justjavac/ReplaceGoogleCDN: 一个 Chrome 插件:将 Google CDN 替换为国内的。 (github.com)
This fixes the Gravatar access issue from the client's side.
However, the Chrome version of this addon requires virtual private network to install...
 

Kevin

Well-known member
I still need it. Onegaishimas.
Please try the attached add-on. :) After installing, go to the Users options in the ACP. The new options are below the normal "Enable Gravatar Support" checkbox.

In the "Gravatar URL" enter your new URL to use like https://gravatar.w3tt.com/avatar/ (or other alternate URL). If the URL you are trying doesn't work just let me know and I'll take a look.

There are some other new options as well based on the Gravatar docs.
 

Attachments

  • CinVin-GravatarTweaks-1.0.0 Alpha.zip
    12.8 KB · Views: 1

Kevin

Well-known member
Please try the attached add-on. :) After installing, go to the Users options in the ACP. The new options are below the normal "Enable Gravatar Support" checkbox.
It has also been added here to the XF Resources area.


If any of the XF staff are reading this, can you delete the attachment in the post above and change it to a link to the XF Resource? Thanks :)
 

Ozzy47

Well-known member
It has also been added here to the XF Resources area.


If any of the XF staff are reading this, can you delete the attachment in the post above and change it to a link to the XF Resource? Thanks :)
Report the post and tell them what you want them to do, best way to get it done.
 

Kevin

Well-known member
Report the post and tell them what you want them to do, best way to get it done.
It's not important enough; if any staff members happened to come across this thread, so be it, but it won't affect anything either way since the attached zip works fine and is the same as what was added to XFRM. If there was anything wrong with the attached file (like a bug or security issue) then I would've already reported it.
 
Top