Search code examples
dnsinfrastructure

Possible reasons for loading scripts/static resources from another domain


I have seen that many websites have a separate domain name (not a subdomain) for loading scripts and static assets.

One example is GitLab loads its scripts from assets.gitlab-static.net when the actual website is on gitlab.com. There are many more I have observed which do the same.

What benefits could be gained through loading a websites own scripts through another domain name instead of using the same domain or a subdomain?

To be clear:

  • I am not asking why the example given does this but what any website in general would gain through this.
  • I am not asking about why user uploaded content is stored on another domain but purely why a websites own CSS/JS is loaded from another domain.

Solution

  • The main advantages include -

    1. A cdn (Content Delivery Network) is used on the other domain(assets.gitlab-static.net) which caches this content to multiple edge locations near to the user accessing it, as these assets might not get modified too frequently. - And its not possible to link few urls of same domain to cdn and others to your own server.

    2. The other domain will be a cookie free domain, so that with every request no session related cookies are sent to server, resulting in utilising lesser bandwidth and faster response.

    3. Other reason could be to use this new domain to apply domain sharding for HTTP 1 / 1.1 connections as a browser opens limited amount (3 or 6 max) of simultaneous socket connections to a domain.