Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to host static contents: Sub-Domain or different Domain?

Is there any benefits to host our application static contents on a completely different Domain rather than host on a Sub-Domain of our main Domain like others? for exampe Microsoft uses i.microsoft.com, Google uses gstatic.com, Yahoo uses yimg.com, Stackoverflow uses sstatic.net

Thanks in advance

like image 508
Sadegh Avatar asked Dec 21 '22 02:12

Sadegh


2 Answers

It should be different domain.

From Yahoo's Best Practices for Speeding Up Your Web Site

When the browser makes a request for a static image and sends cookies together with the request, the server doesn't have any use for those cookies. So they only create network traffic for no good reason. You should make sure static components are requested with cookie-free requests. Create a subdomain and host all your static components there.

If your domain is www.example.org, you can host your static components on static.example.org. However, if you've already set cookies on the top-level domain example.org as opposed to www.example.org, then all the requests to static.example.org will include those cookies. In this case, you can buy a whole new domain, host your static components there, and keep this domain cookie-free. Yahoo! uses yimg.com, YouTube uses ytimg.com, Amazon uses images-amazon.com and so on.

like image 196
Shiplu Mokaddim Avatar answered Mar 04 '23 09:03

Shiplu Mokaddim


Images should be on a different domain (or your CDN's domain). CSS on the other hand, can benefit from being hosted on the ROOT domain, i.e. the same domain as your web server. See this experiment that proves the better load times: http://www.jonathanklein.net/2014/02/revisiting-cookieless-domain.html

like image 37
Ran Rubinstein Avatar answered Mar 04 '23 09:03

Ran Rubinstein