odkkk
Vercel’s domestic acceleration notes after deploying Next.js
Web development · · 4 minutes to read

Vercel’s domestic acceleration notes after deploying Next.js

After the Next.js project is deployed to Vercel, domestic access can be accessed, the domain name is bound and the resolution is pointed to cname-china.vercel-dns.com, and the acceleration is achieved in one move. Attached is a comparison before and after.

Cause: The deployment went smoothly, but it couldn’t be opened in China.

This site is written in Next.js and pushed to Vercel. It automatically builds, automatically signs certificates, and distributes global edge nodes. The whole process is so smooth that you can’t fault it. When you open it overseas, you can open it in seconds and enjoy a full experience.

But as soon as I returned to China, the original shape was revealed - the *.vercel.app domain name assigned by Vercel by default cannot be opened in China. Either the DNS cannot be resolved, or the connection will spin and time out. If you use it yourself, you can hook up with an agent, but this is a site for others to use, so you can’t require every visitor to bring a ladder.

所以第一反应是:绑个自己的域名。绑完之后确实能打开了,但速度依然说不上舒服,首屏经常要等好几秒,偶尔还会卡在某个资源上半天。这就要说说问题到底出在哪了。

What’s the problem?

The domain name *.vercel.app is “polluted” in China, so it is basically useless to use it directly. Binding your own domain name can circumvent this, but tying your own domain name is not enough - the key depends on where you resolve it.

Vercel 绑域名时,默认会告诉你把 CNAME 指向 cname.vercel-dns.com。这个地址走的是 Vercel 的全球边缘网络,节点主要在海外,离国内最近的也就香港、日本、新加坡这些。国内用户访问时常常会绕路,晚高峰更是慢得离谱,表现就是:

  • The first screen was blank for several seconds, but the HTML came back, and the resources loaded slowly.
  • Sometimes it times out directly and refreshes it and it’s fine again. It’s very mysterious.
  • This is especially obvious under mobile networks, but 4G/5G feels like 2G.

It’s probably like this. It’s very difficult to move the loading bar, and most of it is blocked:

Visit effect before optimization

Processing: Change to a domestic parsing entrance

In fact, Vercel has a special entrance for the country, but it will not tell you proactively by default. The solution is just one step - Point the CNAME to cname-china.vercel-dns.com. Note that there is an extra china in the middle.

Specific operations:

  1. Bind domain name in Vercel: Project Settings → Domains, fill in your own domain name, Vercel will prompt you to add a CNAME record.
  2. Go to the domain name service provider to change the resolution: Find the DNS resolution settings and change the value of the CNAME record from the default cname.vercel-dns.com to cname-china.vercel-dns.com. Fill in the host record according to your needs, usually using www or @.
  3. Wait for it to take effect: It usually takes a few minutes to half an hour for the DNS to take effect. Vercel detects that the resolution is correct and will automatically issue an HTTPS certificate, and then you can access it normally.

A little reminder: Whether CNAME can be added to the root domain name (that is, @) depends on your domain name registrar**. Some registrars do not support direct CNAME for the root domain, so they can use the www subdomain and then jump the root domain 301 to www, with the same effect. Most service providers now support the so-called “CNAME forced tiling” (treating the root domain as a CNAME), and Cloudflare and DNSPod are no problem.

就改这么一个字符,从 cname.vercel-dns.com 变成 cname-china.vercel-dns.com

Effect

After the modification, the physical sensation is very obvious. In the same network environment:

  • The first screen opens in seconds, no more waiting for a blank screen
  • Resource loading is smooth and there are no interruptions during the evening rush hour.
  • Can also be used normally on mobile networks

For comparison, it is as follows, the front and back are completely different:

Optimized access effect

To put it simply, it changed from “barely able to open” to “pretty fast”. The core difference is that this china entrance will direct domestic traffic to a closer and more stable node, eliminating the need for a large circle of submarine cables.

Summary

The whole process is actually very simple, there is no advanced operation, the difficulty is just knowing that there is such an entrance. Vercel defaults to a global resolution address, which is not friendly to domestic users; the one with china is prepared for domestic users.

So if you are also deploying Vercel and targeting domestic users, just remember one sentence:

Bind the domain name, then point the CNAME to cname-china.vercel-dns.com, and leave the rest to time.

另外提一嘴,这套方案适合中小站点轻量加速。如果访问量大到一定级别,或者对国内速度要求很高,再考虑前面套一层国内 CDN,不过那是另一篇文章的事了。

Related articles