The use of CDN does improve the loading performance of a web page. This is because of the way the browser caches the content from a given URL. Sometimes, we can gain the following benefits when we use an existing CDN to serve some of the content:
- For some of the frontend libraries that are common, there is a chance that the libraries are already cached by the user's browser while they visited some other website, which include the content from the CDN. This helps us to avoid redownloading those libraries and reduces the bandwidth usage and improves the loading speed of the page.
- CDNs can also route the request to the servers based on the user geography so that the content is downloaded with the least possible latency, thereby improving the loading speed of the page.
To make the browser use the existing connections, we can utilize a concept called KeepAlive
. When the KeepAlive
headers are set in a request, the connection that is used to make the request is kept open by the server for a fixed amount of time in the hope that the same connection can be used for working on another request, avoiding the cost of the initial connection setup for every other request.