If you don’t know, the Gravatar in the comments section of your WordPress website will be downloaded from Gravatar.com’s server, not from your host. Therefore, even if your site is hosted on a server in Vietnam, it will still be affected by an undersea cable problem, especially in the case, the article has many comments. So how to solve this problem to increase the loading speed of your WordPress website? The main solution is to cache Gravatar on the host. In today’s article, I will show you in detail how to do that.
Why does Gravatar affect web loading speed?
As mentioned at the beginning of the article, Gravatar is downloaded directly from Gravatar.com’s server, so you cannot compress to reduce the size or set the cache time on the web browser for them. Furthermore, each Gravatar is an image, so the more Gravatars a page has, the more requests it receives and the slower it loads. Even if your website uses a host located in Vietnam, Gravatar is still downloaded from servers located abroad. That is, the loading speed of the elements on the website will not be the same. Therefore, you will need to cache Gravatar on your host to minimize their impact on web loading speed.
Cache Gravatar with LiteSpeed Cache plugin
If you are using the LiteSpeed Cache plugin on your website, then things will become very easy.
Step 1: All you need to do is access LiteSpeed Cache => Page Optimization =>  Localization => Set up as shown below.
- Gravatar Cache: you leave it in the ON state to enable it.
- Gravatar Cache Cron: you leave it in the ON state so that the plugin automatically refreshes the caches after a set period.
- Gravatar Cache TTL: Gravatar cache time, in seconds. The recommended value is 604800 seconds equivalent to 1 week.
After the setting is complete, click the Save Changes button to save it.
Step 2: Go to a page containing Gravatar, right-click on any Gravatar and select Inspect. If you see a link in the form …/wp-content/litespeed/avatar/…, it means you have successfully enabled the Gravatar cache feature.
Cache Gravatar with FV Gravatar Cache plugin
Step 1: First, you need to install and activate a plugin called FV Gravatar Cache (download).
Step 2: Go to Settings => Discussion => Default Avatar => Choose the default Gravatar which is Mystery Person, Blank, Gravatar Logo or your custom Gravatar. Do not choose the remaining forms (with the word Generated).
Step 3: Access a page or post containing comments with the default Gravatar. Right-click on the default Gravatar and save it to your computer. Check how many pixels it is. For example, 100 x 100 pixels, in step 5, you will set the same size. Rename the image file to default (with .png format).
Step 4: Access the /wp-content/plugins/fv-gravatar-cache/images/ folder via FTP/ SFTP or cPanel/ DirectAdmin’s File Manager. Delete the default.png file contained in the images folder and upload the default.png file you created in step 3.
Step 5: Next, go to Settings => FV Gravatar Cache => Set the necessary parameters for the plugin.
- Custom Cache directory URL: it’s best to leave it blank by default to avoid errors.
- Gravatar size: the size for the Gravatar you want to cache.
- Daily cron: run a daily cron job to refresh caches.
Click the Save Changes button to save the settings when done. Then, click on the Run Cron Now button to start the plugin.
Step 6: Click the show button in the Cache information section, you will see a list of Gravatars (corresponding to emails) that have been cached on the host.
It looks like this.
Pretty simple, isn’t it? Good luck!
During the first load of a page or article, it often takes more time to cache Gravatar, so the loading speed is not fast. However, in subsequent downloads, the loading speed will be greatly improved because Gravatar is already cached.
If you have any questions and suggestions related to the Gravatar cache, please send them to the comment box below for support and answers.