Preface
Originally, I didn't really want to write this article because, fundamentally, concepts like ”custom IP”, ”preferred IP”, and ”preferred domain” are not official terms. To put it nicely, they are ”folk remedies”; to put it bluntly, they are ”heretical paths” (as the Old Kai would say). I have also dedicated a section in a previous article to correct this misconception (see article:Home Data Center Series Cloudflare Tutorial (7): Introduction to CF Worker Features and Practical Operation, Verification, and Related Technical Principles of Implementing ”Budget Version of APO for WordPress” Based on Workers to Accelerate Website Accessdescription regarding the preferred IP section). However, to this day, seeing that many friends still do not understand the principles of Cloudflare CDN accelerating website access, and do not optimize website access according to Cloudflare's official optimization philosophy, but instead spend their energy researching these ”heretical paths” (haven't you seen that Super Saiyan 3 couldn't even gather energy normally in the end?), I decided to write this article after all, at least to help everyone focus their efforts where they truly matter.
Note 1: This article is purely a technical exposition and is not directed at anyone. If I have accidentally offended anyone with my words, please forgive me. Of course, if you have different technical opinions, you are welcome to discuss them in the article's comment section or message board.
Note 2: Although accelerating website access with CDN is just a simple phrase, its actual implementation involves many technical points, let alone Cloudflare's CDN. To explain it clearly, I have to start from the very beginning.
Background Knowledge
Once Upon a Time
Before CDN technology became popular, the traditional way of building websites was mainly based on self-built server rooms using servers to set up web sites. For self-built server room projects back then, you would apply for a line from a broadband operator (at the very beginning, operators only provided 2 Mbps E1 interfaces, and users had to buy a Cisco 2600 router themselves to connect to the operator's E1 interface using an E1 module; the Cisco 2600's built-in 10 Mbps Ethernet port served as the RJ45 interface ultimately provided by the operator's line—looking back now, it's equivalent to buying a Cisco router as a photoelectric converter to connect to the fiber optic provided by the operator, which seems incredibly luxurious, but back then, this configuration was standard), then buy a firewall, use one Ethernet port as a WAN port to connect to the 10 Mbps Ethernet port of the Cisco 2600 router, and another Ethernet port to connect to the internal Layer 3 switch as a LAN port. Then, select one from a bunch of public IPv4 addresses provided by the operator to serve as the NAT address from the internal network to the external network, and select another one on the firewall to map TCP port 80 of that public IP directly to port 80 of the internal server IP, maybe configure a TCP port 21 mapping at most, and a server room construction project was basically complete.
At that time, because there were not many visitors yet (home broadband was not yet popular, seemed to be ISDN?), publishing a website using a single public IPv4 IP + 2 Mbps bandwidth was more than enough. There was no concept of user experience back then; as long as the website page could open, whether it took 5 seconds or 8 seconds didn't seem to matter.
Later, with the rapid development of domestic home broadband and the emergence of multiple competing broadband operators, a new problem arose: China Telecom broadband users experienced extremely slow speeds when accessing websites with China Netcom (now China Unicom) addresses, and the same was true for China Netcom broadband users accessing websites with China Telecom addresses. This was because traffic between operators required inter-network settlement, which was very expensive, so all operators coincidentally restricted outbound traffic.
Therefore, major ICPs (NetEase, Sina, etc.) at that time had to build data centers separately within the networks of China Telecom and China Netcom to ensure that users of different operators could get a good access experience without generating outbound traffic (users of small operators, such as Tietong, had a hard time).
NetEase and Sina only had one external domain name. How could they ensure that when China Telecom and China Netcom users accessed the same domain name, they could accurately access the corresponding NetEase and Sina data centers within their own operator's network? This brings us to the first important technical point: Global Server Load Balancing.
How DNS Works
Before talking about ”Global Server Load Balancing”, we need to review the basic knowledge - “How DNS Works”.
When we surf the Internet normally, we only need to open the browser, enter the domain name we want to access, and press Enter, and then we can browse the web pages at will. However, this process that everyone is used to is actually the result of cooperation among a series of DNS servers, as shown in the figure below:

As can be seen from the figure above: when a user enters the target domain name in the browser (takingwww.tangwudi.comas an example) and presses Enter, the user's operating system will first query the Local DNS server (which is the DNS address usually configured directly on your computer or router, such as 223.5.5.5, 119.29.29.29, 8.8.8.8, etc.) in a recursive manner for the IP address of the domain name they want to access. Subsequently, the Local DNS server will query the IP address of the target domain name from more upper-level DNS servers in an iterative manner and return the result to the user. During this period, the upper-level DNS (root name servers, top-level domain name servers, authoritative name servers) see the Local DNS server asking questions from beginning to end, rather than the user's real IP (mark this point, it is very important).
Note 1: Actually, querying the Local DNS in the very first step is inaccurate. If we want to be precise, the first step should be the browser querying its own DNS cache; if it exists, use it directly, and if not, proceed further. The second step is to call the operating system's function, which should first check if it exists in the operating system's local DNS cache; if so, use it directly, if not, check the local hosts file, and if it is still not there, it will then send a request to the Local DNS.
Note 2: Regarding recursive and iterative DNS queries, interested friends can research them on their own. This is not the focus of this article, just a casual mention.
Global Server Load Balance (GSLB)
Continuing the previous topic, why can Global Server Load Balancing (hereinafter referred to as Global Load Balancing, also known as Intelligent DNS) enable China Telecom users to access the corresponding data center within the China Telecom network, and China Netcom users to access the corresponding data center within the China Netcom network?
The principle is actually very simple. According to the content described in the previous section on DNS principles, upper-level DNS servers can see the requests sent by the Local DNS. Therefore, as long as the authoritative DNS servers responsible for NetEase and Sina domain name resolution can additionally determine the ownership of the Local DNS source IP address: if the Local DNS is a China Telecom address, it returns the IP of the data center within the China Telecom network nearby; similarly, if the Local DNS is a China Netcom address, it just returns the IP of the data center within the China Netcom internal network nearby.
However, the main responsibility of the authoritative DNS server is, after all, DNS resolution, and its load is already heavy, so it is not quite appropriate to make it do extra work. Therefore, this extra judgment work is handed over to a dedicated device, ”Global Load Balancing”: originally, the Local DNS query should have received a result once it reached the authoritative DNS server, but now the authoritative server says one more thing, ”Although I am the boss, I have fully delegated this matter to my subordinate. Here is its address, go find it.” Then, the Local DNS goes through another round of queries (as shown in the red box below):

Note 1: The name ”Global Server Load Balancing” sounds very high-end, but in essence, it is just a normal DNS server. It's just that because it has a built-in national (or global) IP address database, it can determine the ownership based on the source IP of the Local DNS. For example, with a self-built DNS server based on bind9, you only need to create zone files containing different resolution results, and then use the view statement to associate the source IP address ranges of different DNS queries with different zone files to achieve the simplest "smart" resolution.
Note 2: Professional Global Server Load Balancing (such as F5's GTM) has more commercial functions. If deployed in multiple data centers and able to cooperate with each other, combined with multi-egress link load balancing of data centers and multi-active deployment of applications, these combinations can achieve (same-city/remote) disaster recovery data centers, "two locations and three centers", and multi-active data center solutions.
How CDN Works
“Shadow Clone Technique”: Making Origin Content Ubiquitous
One of the biggest problems with traditional self-built websites is that the location of the origin server is unique. For example, if the public IP is 4.4.4.4, then users nationwide (and even globally) can only access this address to get website content strictly according to public network routing. If the network is smooth, it's fine, but if the network is congested or restricted (similar to the previous mutual restrictions between Telecom and Netcom, or domestic users wanting to access foreign websites), the difficulty is no less than the Journey to the West: requiring one to go through eighty-one tribulations.
So, is it possible to make the website content available everywhere and accessible to all visitors instantly while the location of the origin server remains unique? Of course, by using the ”Shadow Clone Technique” on the origin server: CDN.

Although there is only one origin, through CDN, the origin content can theoretically be mirrored to cache servers in various regions across the country (represented by the nginx icon), making the origin ”ubiquitous” while also offloading the performance pressure of the origin to various cache servers (theoretically, many traditional performance requirements on the origin, such as concurrent connections and new connections, are no longer that important):

However, in actual implementation, mirroring all origin content to cache servers is not adopted, because directly mirroring origin content to cache servers would cause the following problems:
Storage efficiency and cost issues
• Massive Data is Difficult to Mirror: The content on the origin server can be extremely massive, containing a large number of files, videos, images, etc. If all origin content is completely mirrored to all cache servers, a huge amount of storage space is required. This would greatly increase the hardware costs for CDN operators, especially since multiple data centers distributed globally would all need to store this data.
• On-Demand Caching is More Efficient: Through an on-demand caching strategy, CDN servers only store content that users have actually requested, reducing unnecessary storage consumption, improving storage efficiency, and lowering costs.
Content Dynamism and Timeliness
• Changes in Dynamic Content: Some content is dynamically generated or frequently updated, such as personalized user pages or real-time news. This type of content cannot be cached long-term and needs to be fetched from the origin server in real-time based on user requests to get the latest version. Therefore, it cannot be fully cached to CDN nodes through simple mirroring.
• Content Timeliness: Some content may have time limits, such as short-term campaign pages, discount information, or current news. Completely mirroring this content may result in expired content still being cached, leading to user experience issues and data synchronization difficulties.
Network Bandwidth and Transmission Costs
• Full Mirroring Increases Bandwidth Requirements: If all content from the origin server is transmitted to cache servers, especially for some large websites or streaming platforms, it will generate huge bandwidth demands. This not only increases the load on the origin server but also significantly raises transmission costs, especially cross-regional data transmission fees.
• Avoiding Unnecessary Traffic: On-demand origin-pull can reduce unnecessary traffic transmission, pulling content from the origin server only when users actually need it. This optimizes the use of network resources and avoids wasting bandwidth.
Complexity of Data Updates and Synchronization
• Frequent Content Updates on the Origin Server: If the origin server content is updated frequently, the CDN needs to continuously monitor and synchronize all cached content, which increases complexity and management costs. The on-demand origin-pull model reduces this complexity, only needing to ensure the latest version when the content is requested.
• Consistency Management Issues: Full mirroring to cache servers means that every time the origin server is updated, all cache servers must be updated synchronously; otherwise, it will lead to content inconsistency. With on-demand origin-pull, CDN nodes can automatically check whether content needs to be updated based on caching policies, effectively reducing the pressure of consistency management.
Differences in User Demand Across Different Regions
• Uneven Distribution of Content Requests: Users in different regions have different demands for origin server content; for example, certain content may only be popular in a specific region. Full mirroring of all content to global CDN nodes would result in a lot of unnecessary data storage, especially for content that is rarely accessed by users. On-demand origin-pull can more intelligently cache relevant content based on the demands of different regions, optimizing the use of storage resources.
Therefore, the final approach adopted is for cache servers to perform an ”origin-pull” (when a CDN node does not have the content requested by the user cached, it needs to forward the request back to the origin server to retrieve the content) when needed, which is like the ”take what you need” concept promoted at buffets.
Note: The ”origin-pull speed” of cache servers is a very important consideration. However, usually, the networks between various domestic CDN providers and domestic cloud host providers are optimized (some are even the same company), so no matter how slow the origin-pull speed is, it won't be too slow, so we won't discuss it much here.
Traditional DNS Scheduling Based on Global Server Load Balancing
Although CDNs can make origin server content ”ubiquitous” using distributed cache servers, how to let users find the cache server closest to them is a question worth studying. The simplest implementation is global server load balancing + cache servers distributed in various locations.
Taking domestic users accessing my blog URL as an example,www.tangwudi.comassuming I have deployed Nginx servers as cache servers in multiple regions across the country, when a user requests to accesswww.tangwudi.com, the global load balancing device that ultimately receives the DNS query request will return a cache server address it considers closest, using the Local DNS address used by the user as a reference, as shown in the figure below:

Therefore, after using global load balancing for DNS scheduling, users in each region will feel that their access speed has greatly improved (local access is naturally fast~).
Note 1: In theory, if the default DNS server address provided by the ISP is used—for example, Chongqing Telecom users use 61.128.128.68, and Chengdu Telecom users use 61.139.2.69—then the global load balancer can accurately determine which ISP's user initiated the DNS request, and the returned nearby IP address will also be the most accurate. However, people may modify their Local DNS address for various reasons (for example, wanting to use Alibaba's DoH, they might change the DNS server address to Alibaba's DNS address: 223.5.5.5). In this case, the nearby address returned by the global load balancer based on the Local DNS server IP may not actually be the closest, but since they are all within the country, any slight slowness is barely noticeable.
Note 2: Actually, there is also a way for DNS requests to carry the user's real IP, so that the global load balancing device can obtain the user's real source IP address, thereby returning the most effective nearby access IP. This technology is EDNS. However, this feature requires support from the DNS client, Local DNS, and the final authoritative DNS server (it is best if all intermediate DNS levels support it), so it is relatively difficult to implement.
Limitations of Implementing CDN Based on DNS Scheduling
In the previous section, I used the simplest implementation based on global load balancing to explain how CDNs work. Strictly speaking, while not incorrect, it has limitations: this approach is usually only suitable for specific, localized needs, such as internal enterprise use or providing services only for a specific region (like domestically). If you want to scale up and expand globally, this approach will cause many problems:
Unable to Achieve Global Traffic Distribution
• Geographical Location Affects Access Speed: An important function of a CDN is to route requests to the server node closest to the user based on their geographical location. A single region is fine, but if the service scope expands globally and still relies solely on DNS or other methods to determine traffic routing, it may lead to inaccurate routing and slower response speeds.
More Complex Traffic Management
• Limitations of DNS Load Balancing: CDNs usually rely on DNS load balancing to achieve traffic distribution. Although DNS load balancing can route based on the Local DNS address (or even the user IP address implemented by EDNS), its accuracy and flexibility are insufficient (not to mention that people like to change their Local DNS addresses), and DNS records update slowly, making it unable to respond to network changes in real-time.
• More Complex Failover: If a node encounters an issue, a CDN using DNS routing may take some time to update DNS records and redirect traffic to healthy nodes.
High Latency and Inconsistent Network Performance
• Increased Cross-Border Traffic Delay: Users' requests may be routed to CDN nodes far away from them, especially when DNS resolution in certain regions is not precise enough. This leads to increased cross-border network transmission times, affecting the user experience.
• Inconsistent Performance: Different users may experience different access speeds due to differences in network paths.
Higher Network Complexity and Operational Costs
• Complex Geo-DNS Settings Required: To achieve global or regional traffic optimization, CDN providers need to invest more time and resources to configure and maintain geo-DNS settings to ensure that user requests can be routed to appropriate nodes as much as possible. This not only increases operational costs but also makes the system more complex.
• Regional Congestion Issues: Certain regional nodes may bear more traffic, making regional congestion issues more prominent.
Poor DDoS protection effectiveness
• Difficult to disperse attack traffic: DDoS attacks may be concentrated on a specific IP address or node, making this node more vulnerable to being overwhelmed and affecting the entire service.
• Harder to achieve global protection: CDN is difficult to disperse and absorb attack traffic through multiple nodes, affecting overall security and stability.
Limited scalability
• Difficult to flexibly expand global nodes: CDN may need to configure the IP address of each node individually, making expansion more difficult and operations more complex.
To deploy CDN globally, the above problems will be encountered, and the key to solving these problems is Anycast IP technology.
Anycast IP Technology
What is Anycast IP technology?
Anycast IP is a network routing technology whose core idea is to assign the same IP address to multiple server nodes in different locations, meaning that multiple servers share one IP address. When a user sends a request to this IP address, the network automatically routes the request to the server node closest or optimal to the user.
Taking the KFC delivery hotline ”400-880-3823" as an example, when you call this number to order food, no matter where you are, the call will automatically connect to the KFC fast-food restaurant closest to you. This restaurant will provide services based on your address. The entire process is seamless to you; you do not need to manually select which store, yet you enjoy the service of the nearest store.
Returning to the previous diagram, if Anycast IP technology is deployed nationwide, and thewww.tangwudi.comdomain name's resolved IP is bound to this Anycast IP of 10.10.10.10, then the global load balancer can completely slack off. Any query received for thewww.tangwudi.comdomain name will be responded to with 10.10.10.10 (of course, generally it won't be that lazy, and it still needs to respond with different Anycast IPs based on the client's region), and each user using this IP as the destination IP for access can still access the cache closest to them:

After CDN uses Anycast IP technology, the 6 problems mentioned in the previous section are all resolved:
Global or regional traffic optimization
• Fast response: Through Anycast IP technology, user requests are automatically routed to the nearest CDN node. This significantly improves user access speed, especially in cases of cross-border access or widely distributed global users, reducing latency.
• Intelligent traffic distribution: Anycast allows the same IP to be shared across multiple nodes globally, so no matter where users are, their requests are intelligently distributed to the optimal server, thereby optimizing performance.
Simplified traffic management
• Real-time routing optimization: Anycast IP automatically selects the best path without the need for frequent updates or manual management like traditional DNS load balancing. This reduces the complexity of traffic management and improves network flexibility.
• Fast failover: Anycast can quickly switch traffic to other healthy nodes when a node fails, ensuring service continuity without relying on slower DNS updates.
Lower latency and consistent network performance
• Geographic location advantage: Anycast IP can ensure users connect to the closest node based on their physical location, which means reduced network latency and more consistent performance for global users.
• Eliminate cross-border access latency: For cross-border or cross-regional traffic, Anycast can route requests through the optimal path, reducing network latency issues in data transmission.
Simplified network management and cost control
• Automated traffic scheduling: Anycast simplifies GeoDNS settings, automatically routing user traffic to the optimal node, reducing manual configuration complexity and management costs.
• Effective traffic allocation: By balancing traffic, overloading of a single node is avoided, improving overall network efficiency and performance, and reducing additional maintenance costs.
Enhanced DDoS protection
• Disperse attack traffic: When a DDoS attack occurs, Anycast technology can disperse the attack traffic to multiple nodes, reducing the pressure on a single node, thereby effectively mitigating the impact of the attack and improving network security.
• Global protection capability: Anycast allows attack traffic to be absorbed and dispersed globally, no longer limited to a specific region or node, which improves the overall network protection effectiveness.
Flexible scalability
• Simplify global node expansion: Through Anycast IP, CDN providers can easily expand new nodes globally without configuring different IP addresses for each node. This expansion method is more flexible and faster, helping CDN providers cope with growing traffic demands.
• Balance network load: When Anycast distributes traffic globally, it makes the traffic more balanced, reducing the risk of single-node overload and improving service stability and reliability.
After using Anycast IP technology, the advantages of CDN lie in faster access speeds (better than slow, round-trip DNS queries), more flexible traffic management, more consistent network performance, stronger DDoS protection capabilities, and more flexible scalability. These advantages enable CDN to better provide high-quality services to users globally or in large-scale regions, and ensure network stability and security. However, compared to traditional DNS-based scheduling methods, the deployment difficulty of Anycast IP is much higher (involving backbone network optimization), so it is not suitable for small-scale CDN providers or enterprise self-built CDN scenarios.
Note: Although Anycast IP is indeed an IP address, it is not the ordinary IP address (unicast IP) we see everywhere. It is actually more like a door with an uncertain exit disguised as an IP address (just like Doraemon's Anywhere Door, which looks like an ordinary door, but opening it can lead to anywhere, so even if you open the door and see Location A at one moment, it might become Location B the next moment).
Using Cloudflare CDN to Accelerate Website Access
Global CDN Based on Anycast IP
Cloudflare is a service provider offering comprehensive global solutions (including CDN, DDoS attack protection, and other services). Most importantly, Cloudflare also offers a Free plan that benefits many individual webmasters (see article:Home Data Center Series Cloudflare Tutorial (1) Introduction to CF and its Benefits to Individual Webmasters), which includes a CDN with unlimited traffic. One of the key reasons it can be so generous is its private backbone network and data centers deployed with Anycast IPs worldwide:

Current Status of Cloudflare in China
Unfortunately, even a powerhouse like Cloudflare cannot build its own backbone network in China. The current compromise is to cooperate with JD Cloud, using JD Cloud's network to extend into the country, which leads to two problems:
The cost of the domestic network portion remains high
Would JD let Cloudflare get a free ride? Cloudflare can save costs elsewhere because of its self-built network. Now, having to cooperate with a domestic cloud provider, the high cost is easily imaginable. Therefore, for Cloudflare, the main purpose of using JD Cloud's network is to satisfy its own enterprise-level key accounts (such aswww.qualcomm.cn,www.visa.cnetc.) for their domestic websites. For this reason, a China-specific service called ”China Network Access” was introduced, which Free plan users can certainly only drool over:

The ”China Network Access” in the red box in the image above, which refers to direct access to JD Cloud's 30 domestic data centers, has two meanings:
- The IP resolved for the domain name is JD Cloud's domestic public IP (the resolution result returned by global load balancing based on geography). Therefore, domestic users can directly use the nearest domestic JD Cloud IP to access Cloudflare enterprise users' websites. You can ping this yourself using a normal network
www.qualcomm.cn和www.ivsa.cnto find out. - If the origin server of a Cloudflare enterprise user's domestic website is also hosted domestically, when domestic users cannot find the required content in the cache server of the nearest JD Cloud data center they access, the cache server can fetch the source directly from this JD Cloud data center.
Control over the network is far inferior to its self-built backbone network
This is also normal. After all, borrowing JD Cloud's network means it's impossible to configure it however they want like their own network. Moreover, domestic networks inherently have major restrictions, making many technologies Cloudflare excels at (such as Anycast) ineffective in China:

This also forces Cloudflare to adapt to JD Cloud's network conditions to build services with ”Chinese characteristics,” which consequently results in Cloudflare's enterprise users' websites resolving only to ordinary domestic public IP addresses (non-Anycast IPs) in China.
Impact on Individual Webmasters Using the Free Plan
The direct consequence of the above two problems is that any of JD Cloud's domestic networks will only serve Cloudflare enterprise-level users who have purchased the ”China Network Access” service, and have nothing to do with users subscribed to other plans. In other words, except for those enterprise-level users, for users subscribing to plans including the Free plan (as well as other paid plans), Cloudflare is equivalent to having no network in China (which it didn't have to begin with~).
This actually has no impact on Free plan users (and the websites they build) whose target audience does not include China. After all, Cloudflare data centers are everywhere around the world. When visitors from other regions access websites built by Free plan users, they only need to use the Anycast IP resolved by DNS to be directly assigned to the nearest data center. If they need to fetch from the origin, they can do so directly from this nearest data center. Although they cannot use many advanced features (such as ”Argo Smart Routing”), well, the foundation is there, so it won't be too slow (due to physical proximity).
However, it is miserable for individual webmasters (including myself) on the Free plan whose target audience includes China. Because there is no network in China, and according to Cloudflare's network resource management and optimization strategies, access requests from domestic visitors are usually routed by Cloudflare's Anycast IP to data centers in the western United States (with a high probability of the San Jose data center). The direct result is slow access for domestic users.

Why are domestic Free users assigned to the San Jose data center? The reasons are probably as follows:
• 1. Cost Management: Cloudflare's Free plan is free, and the company usually prioritizes allocating higher-quality resources (such as high-quality data centers in Asia) to paying users. Data centers in the western United States are relatively cheaper (the main reason) and closer to mainland China (geographically close, shorter submarine fiber optic cables, lower latency), making them a common allocation destination for Free users.
• 2. Regional Network Restrictions: Mainland China has certain restrictions and regulatory requirements on foreign network services. Cloudflare's traffic in mainland China requires cooperation with local operators and data centers, which may also cause non-paying users' traffic to be preferentially routed to US data centers, especially western US data centers, due to their relative proximity.
• 3. Network Load Balancing: Cloudflare's global network distributed traffic scheduling system selects appropriate data centers to handle traffic based on network load conditions. During peak traffic hours or when specific regions experience heavy loads, Free plan users may be allocated to more distant servers (such as the western US) to relieve the burden on Asian data centers.
• 4. Partnerships: Cloudflare currently partners with JD Cloud in China (previously Baidu Cloud). Although this partnership provides better access speeds for mainland Chinese users, it prioritizes enterprise users who have purchased China network access services, causing Free users' traffic to bypass through overseas nodes.
In-depth Analysis of Why Domestic Users Experience Slow Website Access
In the last section, I mentioned that domestic users experience slow speeds when accessing websites built by personal webmasters on Cloudflare's Free plan because they are allocated to data centers in the western United States. People might take this for granted: because it's far. While this is indeed the case, it is also necessary to further break down the specific reasons for the slowness into multiple steps for study, so as to facilitate targeted optimization later:
Let's look at the complete 4-step process, including origin pull, when a domestic user's access request misses the cache in the San Jose data center:

If we make a simple time estimation based on the above scenario, we can see that if an origin pull is required, calculating a single-trip time as ”1”, then the total time is "4".
Note 1: Whichever data center the visiting user is allocated to, if there is a subsequent need for an origin pull, the origin pull request will be ”initiated” from that data center. This is an ironclad rule and is the same for subscribers of all Cloudflare plans (including Enterprise users). The only difference is that Enterprise users have more options from the start (such as more and closer data centers). Please keep this in mind.
Note 2: This is just the simplest simulation. In reality, the total time spent opening a page is determined by how many round trips of steps 1 and 2, and how many round trips of steps 3 and 4 actually occur.
Conventional Optimization Ideas
The so-called conventional optimization approach is to optimize the 4-step access process mentioned in the previous section: using cache rules or page rules to minimize the occurrences of steps 3 and 4, ideally to zero. Simply put, it is ”Accumulate grain widely, delay claiming the throne,Cache more, pull from origin less.”
Static Sites
The optimization goal for this type of site is: full-site caching without origin pull (so-called "no origin pull" means that except for the first origin pull, subsequent ones are not needed). There is no need to overcomplicate things; just configure Cloudflare's cache rules to cache all necessary content such as JS, CSS, HTML, PNG, etc. The subsequent access speed won't be too slow (although the tested speed is certainly not under 100ms like domestic servers, the actual experience is not much different), and you don't have to worry about DDoS attacks.
You can experience this using the Hexo test site I deployed on Cloudflare Pages (it only has the default homepage, so please bear with it):https://hexo.tangwudi.com。
Dynamic Sites
The optimization goal for this type of site is: cache as much as possible, pull from origin as little as possible. However, dynamic sites are different from static sites, and some content cannot be cached. Taking WordPress as an example, specific URIs (content starting with “/wp-admin”, ”/wp-login”, ”/wp-comment”, etc.) and requests containing specific cookie fields (“wp-“, ”logged_in”, ”wordpress”, ”comment_“, ”woocommerce_“) cannot be cached, so this part of the content needs to be excluded, while everything else should be cached. You need to configure a layered cache rule strategy in order of priority from top to bottom (for detailed configuration methods, see the article:Home Data Center Series Cloudflare Tutorial (6) CF Cache Rules Feature Introduction and Detailed Configuration Tutorial)。
Here is a comparison of the results. For my test WordPress site, when accessed directly without using any caching rules (meaning completely going through steps 1, 2, 3, and 4), the time from sending the request to starting to receive data from the server (Cloudflare data center) (TTFB) was 2.74 seconds:

And after using cache rules to cache all cacheable content, the TTFB time became 1.14 seconds:

To be fair, this is already pretty good.
Note 1: TTFB (Time To First Byte) is ”the total time from sending a page request to receiving the first byte of response data”. It includes DNS resolution time, TCP connection time, HTTP request sending time, and the time to obtain the first byte of the response message. Simply put, it is the time from when we enter a domain name in the browser and press Enter until we see the page content start to appear. TTFB is very important because normally, when we open a web page, how long it takes for the entire page content to fully render is actually not very sensitive to users; what is truly sensitive is how long after entering the domain name and pressing Enter the page content begins to load.
Note 2: The Tiered Caching feature is very important and must be turned on:

The Tiered Caching feature has a great optimization effect on origin pull. Although domestic users must initiate origin pull requests from the San Jose data center, after enabling the Tiered Caching feature, they do not have to pull from the origin directly from San Jose. Instead, it queries a top-tier data center closer to the origin (such as a data center located in Asia). If it is not in the top-tier data center's cache either, the top-tier data center will initiate an origin pull request to the origin. After receiving the origin's response, it will inform the San Jose data center of the content through Cloudflare's internal network. This is faster than directly pulling from the origin from the San Jose data center via routing over the public network. Tiered Caching is the only mechanism that can indirectly achieve the ”nearest origin pull” effect when an origin pull is needed in Cloudflare's Free plan.
Advanced Optimization Ideas - Workers (Suitable for Dynamic Sites)
The so-called advanced optimization idea is to no longer be limited to Cloudflare's traditional caching features (based on cache rules and page rules), but to use the Worker feature, combined with a JS script ”Edge Cache HTML” previously released by Cloudflare on GitHub, to control caching features more flexibly and intelligently (for detailed configuration, see the article:Home Data Center Series Cloudflare Tutorial (7): Introduction to CF Worker Features and Practical Operation, Verification, and Related Technical Principles of Implementing ”Budget Version of APO for WordPress” Based on Workers to Accelerate Website Access)。
Compared with Cloudflare's traditional caching features, the Worker-based optimization method is more suitable for dynamic websites:
- Fine-grained cache control
• Worker Optimization Allows you to customize cache policies based on conditions such as specific request types, URLs, and user status. For example, you can cache more content for non-logged-in users while dynamically generating personalized parts for logged-in users. This flexibility is something traditional cache rules cannot achieve.
• Can be done through Custom Cache Key to determine which requests share cache and which requests cache independently, thereby improving the cache hit rate. - Partial Caching of Dynamic Content
• Workers allow you to cache the static parts of dynamic pages. For example, the main body of a blog post can be cached, while the personalized parts for logged-in users are fetched from the origin server. This Partial Caching(Partial Caching) can significantly reduce server load and improve user response speed. - Higher Cache Hit Rate
• Using Workers can improve the cache hit rate, especially on multi-user sites with complex content. By finely controlling caching policies, you can maximize cache utilization and reduce unnecessary origin requests. - Avoid Excessive Origin Requests
• Workers can set different cache TTLs for certain resources, or implement Cache Prefetching, returning stale cache when a user requests it, while asynchronously fetching new content from the origin to update the cache without affecting the user experience.
If your website has a lot of dynamic content and user interaction, the Worker optimization method will indeed bring significant performance improvements. For example, after using the Worker optimization method on my test WordPress site, the TTFB was further reduced from 1.14 seconds with the traditional caching method to 332.52 milliseconds:

Note 1: Still, do not forget to enable the Tiered Cache feature.
Note 2: For websites that mainly provide static content, a properly configured traditional caching method can already achieve good results, so there is no need to fuss with this.
Additional Knowledge: Argo Smart Routing
What is ”Argo Smart Routing”?

This feature actually has little to do with individual webmasters like us who mostly look for free options (it is paid and so expensive), but because it is a genuine network-level optimization, I think it is still worth mentioning.
“The ”Argo” in ”Argo Smart Routing“ does not have a publicly disclosed specific acronym explanation, but it can be understood as a symbolic name representing a solution for optimizing network paths. The name ”Argo” is likely borrowed from the ”Argonauts“ in Greek mythology, who were heroes embarking on long voyages aboard a ship named ”Argo". This corresponds to the core concept of Argo Smart Routing—delivering data quickly and intelligently across the global network via the optimal path.
So, what is ”Argo Smart Routing”?
Argo Smart Routing is an advanced network optimization service provided by Cloudflare that optimizes internet traffic in the following ways:
• Smart Routing: It dynamically selects the fastest and most reliable path through Cloudflare's private network based on real-time network conditions, rather than using traditional BGP-based routing.
• Reduced Latency and Packet Loss: By avoiding congested or poorly performing network paths, Argo can significantly reduce latency and improve the reliability of content delivery.
• Reduced Origin Response Time: Especially for origin requests, Argo can find faster paths, thereby reducing the time it takes to fetch content from the origin and improving the overall response speed of the website.
“Optimization Principles of ”Argo Smart Routing"
Let's use the access flow in this diagram as an example to illustrate:

Smart Routing (taking domestic users -> San Jose data center as an example)
Without Argo Smart Routing:
When domestic users visit, their requests are assigned by Cloudflare's Anycast IP to the San Jose data center. Without Argo, users” requests are transmitted using the default routing method, which might go through the following path: ”Domestic → Southeast Asia → Pacific Undersea Cable → San Jose". In some cases, this path may be congested or have high latency, affecting the user's access experience.
With Argo Smart Routing:
Argo Smart Routing It can dynamically detect network conditions on different paths and automatically select paths with lower latency and less congestion. When Argo detects latency or congestion on the path using the default routing method, it can choose a faster path, such as: ”Domestic → Hong Kong → Pacific Undersea Cable → San Jose”. In this way, although domestic users are still assigned to San Jose data center, but the data transmission path is optimized, reducing round-trip time.
Reduced Latency and Packet Loss (taking San Jose data center -> domestic users as an example)
Without Argo Smart Routing:
When transmitting data from the San Jose data center back to domestic users, traditional routing may cause congestion on certain paths or unstable network nodes, leading to packet loss. For example, if data packets pass through a congested link (such as a certain undersea cable line), users may experience data loss, slow page loading, or even need to retransmit packets multiple times, resulting in higher latency.
With Argo Smart Routing:
“Argo Smart Routing” can monitor the health of different network nodes to avoid links with high packet loss rates or network instability. When Argo detects packet loss or high latency on a certain path from “San Jose → Domestic”, it will automatically select a more reliable path, such as: ”San Jose → Singapore → Domestic” or ”San Jose → Hong Kong → Domestic”. Through this smart adjustment, the packets received by users are more stable, reducing packet loss and ultimately improving the access experience.
Reduced Origin Response Time (taking San Jose data center to origin servers in China as an example)
Without Argo Smart Routing:
If the San Jose data center does not cache the content requested by domestic users, it will initiate an origin request to the origin server located domestically. Without Argo, this origin request will use the default internet routing method, which might go through the following paths: ”San Jose → Southeast Asia → China” or “San Jose → Pacific Undersea Cable → China”. These paths may be longer or have congestion issues, leading to increased origin response time.
With Argo Smart Routing:
“Argo Smart Routing” can select the best origin path from the San Jose data center to the domestic origin server based on real-time network conditions. When Argo detects congestion at a node in the origin path, it will bypass the congested node and choose a faster path, such as: ”San Jose → Hong Kong → Beijing” or “San Jose → Singapore → Beijing”. Through this smart routing, the origin path is optimized, and the time to retrieve data from the origin server is greatly reduced.
It can be seen that although steps 1, 2, 3, and 4 still exist, from the network routing level, it has become much more flexible and efficient.
Note 1: ”Argo Smart Routing” can be considered a cure-all; besides HTTP-type applications, it is effective for any other type of application. This is the beauty of ”network-layer optimization” (as opposed to application-layer optimization).
Note 2: It also needs to be used in conjunction with the Tiered Cache option.
Summary of Cloudflare Website Optimization Philosophy
From the various website optimization methods provided by Cloudflare, combined with the default nearest-access policy, we can summarize Cloudflare's 3 optimization philosophies in optimizing website access:
- Proximity Principle
This proximity principle includes assigning visiting users to the nearest Cloudflare data center (which is why Cloudflare needs to establish a large number of data centers globally, with a few countries excepted), and also includes the data center fetching from the nearest origin.
Note: Regarding fetching from the nearest origin, in addition to enabling the ”Tiered Cache” option, using the Tunnel method to fetch from the origin can sometimes be more advantageous than using the public IP address method. This is because the Tunnel establishes a private path from the Cloudflare data center to the origin server, which may bypass potential public line congestion and latency when fetching via public IP addresses. However, the specific performance improvement will depend on network conditions, the physical location of the origin server, and the distribution of Cloudflare data centers. If the public network connection between the origin server and the Cloudflare data center is good, the performance difference may not be significant.
In theory, Free plan users of Cloudflare Tunnel ”potentially” can be assigned to any Cloudflare data center, including those in Asia. Cloudflare will automatically connect the tunnel to the data center it deems optimal based on network conditions, traffic load, and other factors. Therefore, if you are in Asia or most of your users are in Asia, Cloudflare may connect the tunnel to the Asian data center closest to you.
However, for the tunnels of Free plan users, Cloudflare's global network resource allocation may be subject to certain limitations. Compared to paid plans, Free users' tunnels are more likely to be allocated to more distant data centers during peak traffic hours. For example, even if you are geographically closer to a data center in Asia, Cloudflare may still allocate you to a more distant location, such as a data center in the United States, due to load or other reasons.
Therefore, under the Free plan, there is ”no absolute guarantee” that Free plan users' tunnels will be connected to data centers in Asia, but it is possible (it would be impossible if using the public IP address method for origin pull~), depending on Cloudflare's dynamic network allocation.
Still taking the previous example: domestic users are allocated to the San Jose data center. If the San Jose data center's cache does not have the corresponding content, it will request content from the top-tier data center (Asian data center) according to the requirements of tiered caching. When the top-tier data center finds that its own cache also does not have it, if it is a public IP address origin pull method, it will directly initiate an origin pull to the origin server through the public network; if it is a tunnel origin pull method, the tunnel will take over this process, ensuring a direct origin pull through a secure dedicated line, bypassing the public internet, thereby enhancing security and reducing network instability. Therefore, using ”tunnel origin pull” is to some extent equivalent to using ”public IP address origin pull” + ”Argo Smart Routing”, allowing you to get a bit of a free ride once again.
However, the tunnel method is not a panacea. Currently, the most reliable way to build a website using the tunnel method in China is to use domestic cloud hosts. For home broadband website building, it depends on the local broadband operator's access policy for Cloudflare's IP address ranges. In some places, degradation has been implemented, which may cause the tunnel itself to be unstable. Of course, most broadband connections should be fine.
- Route Optimization
After getting closer, there is still a way to go. For the remaining path that must be taken, optimize it to the best of your ability to make this path easier to travel (Argo Smart Routing).
- Utilize caching as much as possible
Even if the road is easy to walk, walking too much will still make your feet sore, so it is best to walk less. For example, in the past, you had to get up early to go to the town market to buy vegetables and meat, but now you only need to buy them at the farmers' market at the entrance of the village.
According to Cloudflare's thinking, points 1 and 2 are its business, while point 3 is what it hopes we will do ourselves.
Folk Remedies: ”Custom IP”, ”Preferred IP”, and ”Preferred Domain”
“The origin of ”custom IP”, ”preferred IP”, and ”preferred domain name": Because domestic users in China are allocated to the San Jose data center in the western United States when accessing websites built by Free plan users using the resolved Anycast IP, resulting in slow access, these Free plan users wanted to use their domestic IPs to resolve the website domain names of some Cloudflare enterprise customers (such as www.visa.com). After obtaining their Anycast IPs, they use specific software to test these Anycast IPs (or simply use the IP address ranges published by Cloudflare) to find the IP with no packet loss and the lowest latency, and finally manually change their website's resolved IP to this IP.
Actually, this idea itself is good. It aims to solve the problems of steps 1 and 2 in the previously mentioned steps 1, 2, 3, and 4, and also to manually implement the first step of Cloudflare's website optimization philosophy: the proximity principle. However, although this method may seem to “temporarily” improve the access speed of domestic users in certain specific situations, it is not a reliable or recommended practice in the long run (after I manually changed the IP in the past, I had to visit my blog every now and then to see if the speed was normal, and finally got annoyed and changed it back to the default resolution), for the following reasons:
The design of Cloudflare's Anycast mechanism itself
• Cloudflare's Anycast IP allocation mechanism is global, relying on dynamic routing, which is automatically optimized and allocated by Cloudflare based on network conditions and geographical location. Although different Anycast IP ranges correspond to different data centers, routing is not determined simply based on the IP address, but is dynamically decided based on real-time factors such as network topology, latency, and congestion.
• Even if you manually specify a certain IP address, Cloudflare may still dynamically adjust the traffic path based on global network conditions, so your manual modifications may not always maintain effective optimization results.
Violating Cloudflare's best practices and service design
• Manually changing the Anycast IP does not comply with Cloudflare's best practices. Cloudflare is designed for users to use its provided DNS service and intelligently allocate the best path and IP through its network.
• Forcing a binding to a specific IP may cause the traffic to be identified as abnormal traffic by Cloudflare, affecting access stability or leading to other unpredictable issues, such as SSL certificate validation problems, performance fluctuations, etc.
Changes and uncontrollability of IP addresses
• Cloudflare regularly adjusts IP ranges in different regions, and certain specific Anycast IP ranges may be reallocated or rerouted to other regions. If you manually specify an IP, it may be routed to a different region after some time, resulting in unstable access speed (taking Doraemon's Anywhere Door mentioned in the Anycast IP section earlier as an example, when you push open the door at some point and see Chengdu outside, and after closing the door you assume it is always Chengdu outside, but in fact, the next moment it is already Chongqing outside—well, it's a bit like Schrödinger's cat, you don't know the result without actually opening the door).
• In addition, Cloudflare provides different levels of service for different customers (such as the Free plan and the Enterprise plan). Manually resolving to the IP ranges of enterprise customers may lead to potential access restrictions or instability, because the allocation and resource scheduling of these IP ranges are optimized for enterprise-level customers, and the Free plan may not enjoy the same priority:

Besides, do you really think Cloudflare doesn't know when Free plan users manually point their resolved IPs there? And that they haven't taken any precautions against this situation? They only need to enable SNI-based tiered monitoring on these IP ranges: only access requests belonging to the website domain names of enterprise plan users are processed correctly, and all others are treated according to the default policy, letting them do whatever they want.
CDN's intelligent optimization features are bypassed
• Although Cloudflare's free plan does not have all the enterprise-level optimizations, it still utilizes Cloudflare's global network and caching system. Manually binding a certain IP will bypass Cloudflare's intelligent optimization and routing, which may instead cause you to lose certain optimization effects, especially when network conditions change.
Potential legal and terms of service issues
• This practice may violate Cloudflare's Terms of Service, especially if you use unofficial means to obtain the IP addresses of specific enterprise customers for manual resolution. Cloudflare may take action against such behavior, up to and including terminating service.
Actually, the reasons above are just the official statements on the surface. The reason I truly do not recommend it is that it is too much of a hassle. If you have the energy to repeatedly mess with IPs, first ask yourself: Is the caching strategy configured properly? Is all the content that should be cached actually cached? Have you tried using Workers optimization for WordPress-type dynamic sites? After configuration, have you minimized origin pull requests as much as possible? You should know that what affects the website experience most is a TTFB that is too long and frequent origin pulls. If these are all configured properly, for a WordPress-type dynamic personal blog website, using Workers optimization to open pages can achieve a TTFB experience of a few hundred milliseconds; or using traditional caching methods to open pages can achieve a TTFB experience of over 1 second. Isn't that enough to support normal access to a personal blog?
In a word: even if we are just free riders, we should still be civilized and dignified free riders~.
Summary
I've finally finished writing, so tired. Originally, I just wanted to express the meaning of the last paragraph, but then I realized that without any evidence, it wouldn't be convincing. To be persuasive, I first needed to explain Cloudflare's optimization philosophy. Then I thought, since that's the case, I'll just explain Cloudflare's optimization philosophy clearly first. But then I found that to explain Cloudflare's Anycast IP clearly, I needed to compare it with how traditional CDNs work. Following that, I thought I might as well just explain how traditional CDNs work, but that involved intelligent DNS scheduling for global load balancing. Finally, when writing about intelligent DNS scheduling for global load balancing, I realized that to explain it clearly, I first had to explain the basic working principles of DNS... and before I knew it, I had written so much. I'm truly amazed at myself...
However, it was still very rewarding. Previously, there were a few concepts that I only half-understood and didn't grasp thoroughly (including the highly important Tiered Cache feature, which I had mentioned and recommended enabling before, but didn't pay too much attention to), and there were even some misconceptions (I previously thought Argo Smart Routing would change the data center that initiates the origin pull request). But for the sake of writing this article, I've finally figured it all out (it's really important to turn simple ideas into concrete words). Therefore, this article can also serve as a higher-level overview and summary of all the Cloudflare-related content I've written before.
Note: If any friends do not understand many of the concepts in this article, you can find them inCloudflare Learning Mapto search, and perhaps you can find the answer.
I'd really like to ask the blogger, is a website like the URL below actually lacking any room for optimization? (It takes over 10 seconds to open on domestic networks...🤦)
Are all the techniques you explained in your blog post useless here?
https://www.luigimangioneinfo.com/cdn-cgi/trace
Are all the techniques you explained in your blog post useless here?
https://www.luigimangioneinfo.com/cdn-cgi/trace
And this site itself is a typical statically generated page, which is actually very suitable for CDN caching. If the caching strategy is correctly configured on the Cloudflare side (such as allowing HTML caching instead of validating with the origin every time), the access latency can usually drop significantly. So this example is not "lacking room for optimization," but rather the optimization point lies in the cache design, not other aspects. You can check out my article specifically about Cloudflare cache configuration.
The core reason why this site is slow is actually not the network routing, but its caching strategy: looking at the response, it uses Cloudflare in front, but caching is not actually enabled (cf-cache-status is DYNAMIC). Every request goes back to Netlify for processing, which means the CDN layer is not playing its intended acceleration role.
And this site itself is a typical statically generated page, which is actually very suitable for CDN caching. If the caching strategy is correctly configured on the Cloudflare side (such as allowing HTML caching instead of validating with the origin every time), the access latency can usually drop significantly. So this example is not "lacking room for optimization," but rather the optimization point lies in the cache design, not other aspects. You can check out my article specifically about Cloudflare cache configuration.
Got it. I will also send the URL of this blog post of yours to that website's administrator via email 📬 so they can learn from it too.
Otherwise, the loading speed is really too slow. 😲
Thank you for your patience, blogger 🙇, and for using a real example to analyze the specific reasons for me. Thank you. 💋
ヾ(≧∇≦*)ゝ
Otherwise, the loading speed is really too slow. 😲