Home > Article > Backend Development > javascript - Why do many websites use another domain name (such as xxstatic.com) to access static resources?
For example, Baidu uses bdstatic.com or bdimg.com to access static resources. Is there any point in doing this? Isn’t it better to go directly to static.baidu.com? Why waste a domain name?
For example, Baidu uses bdstatic.com or bdimg.com to access static resources. Is there any point in doing this? Isn’t it better to go directly to static.baidu.com? Why waste a domain name?
Second-level domain names are generally cached by CDN to speed up customer service access.
In addition, browsers have limited resources to load a domain name concurrently.
First, in order to prevent domain name cookie scope pollution, needless to say this
The second browser limits the number of concurrent requests in the same domain (6). For example, if there are 10 static resources under a domain name, only 6 will be loaded for the first time, and the other four will be loaded after loading is completed
There are too many things, divided into categories to relieve the pressure on a single server
That’s what I think
I feel like the main domain name has other uses! After all, static files don’t need to look at the domain name!
There is nothing to waste in a domain name. . The most valuable thing is the server. .
The browser has a limit on the number of concurrent users for the same domain name. Different browsers are different. Too many resources will cause congestion and slow loading.
In addition, generally static resources will be provided with CDN to facilitate management.
The two domain names of Baidu you gave as an example may also be due to historical reasons, or multiple domain names are used between different teams
There will be many cookies under the main domain name, which will be brought when making requests. However, these cookies are not needed when requesting static resources, which is a waste of traffic. At the same time, setting up a new domain name is also convenient for CDN caching. There is also the consideration of concurrent browser loading.
Let me talk about the website of my previous unit, where dynamic language and static resources were managed separately (static resources were placed on Qiniu, and the main server was Alibaba Cloud). There are following reasons
Reduced costs, the price of storing static resources is cheaper than that of dynamic resources.
Reduces the load on the dynamic language server. The server that stores the dynamic language may also run other programs, not just this website.
That’s the one upstairs, which improves the efficiency of users accessing the website.
It is also fault-tolerant. If the main server is paralyzed, static resources can still be loaded, so everything is not in vain.
...It’s all upstairs.