Accelerate WordPress with CDN and Cache Servers
It has been a long time since I last wrote a blog post. In the past few days, I updated the architecture of Infinite Script to accelerate the speed for Chinese users. In this article, I share the new architecture of our website with you, illustrated in the figure above.
Optimizing a CDN for Static Content Delivery
Static content does not change over a period of time. If it does change, the changes are predictable. Static content includes images, CSS sheets, JavaScripts, and PDF files. Because of this, CDNs can cache a copy of the content at their edge servers. They can then serve it whenever a client requests it. CDNs are best at optimizing the delivery of static content from edge servers to users. Therefore, we use the CDN from Alibaba Cloud.
As we all know, the edge servers in CDN need to get static files from the original site if a file is not cached by them. The original site is located in the US, so it takes a long time to get files from the original site for edge servers in Mainland China.
To solve this problem, we create a secondary cache server for edge servers in Mainland China. We use the Elastic Compute Service (ECS) provided by Alibaba Cloud. The original site is set to this secondary cache server for edge servers in Mainland China. Of course, this secondary cache server is located in Mainland China.
The secondary cache server works with the same principle as the edge servers do. If the requested file does not exist on the server, it fetches the file from the server located in the US and then saves it on the disk. There is an index.php in the web root directory for handling uncached files.
Optimizing a CDN for Dynamic Content Delivery
WordPress is based on PHP and relational databases (e.g., MySQL). The pages are dynamically generated when users request them. Generating pages from PHP is not time-consuming, however, connecting to the server hosting WordPress takes a long time for users in some regions of China.
We generate a static version of the WordPress website with WP2Static. Then, the static version is pushed to a CDN service powered by UpYun. You may ask why don’t I use Alibaba Cloud CDN here? Because UpYun provides an FTP service which can easily be integrated with WP2Static.
So, Chinese visitors see a static version of the website, which means the search function does not work. The comment system of WordPress was replaced by Disqus several years ago; unfortunately, Disqus is blocked in Mainland China.
In future work, I will solve the problem in searching and commenting for users from Mainland China.
Note: This post describes the WordPress-based architecture of Infinite Script as of 2019. The site has since migrated to a Hugo static site, so this exact setup is no longer in use. The CDN and cache-server approach, however, may still be helpful for other WordPress sites that need to speed up delivery for users in Mainland China.

The Disqus comment system is loading ...
If the message does not appear, please check your Disqus configuration.