Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hosting images on separate sub domains

My company hosts about 30 web sites all sharing the same code base and reusing many of the same images. Right now, the images for all of the sites are hosted on the one domain, and then every other site has to link to those images.

i.e., www.example.com/images/hello.jpg

and on www.example2.com we have something like: <img src="http://www.example.com/images/hello.jpg" />

Recently someone told me that I should be putting all of these shared/static images on a subdomain, but I don't see the advantages to this. I have heard that there might be a slight speed increase, but I've also heard that it can complicate things. Can someone elaborate?

like image 306
Brad Avatar asked Oct 06 '09 20:10

Brad


People also ask

Do subdomains need their own hosting?

Because subdomains are regarded as separate websites by Google, they also need to be hosted on separate hosting plans. This means that you will need to pay a separate hosting fee for each subdomain.

Can you have 2 sub domains?

A subdomain is an additional part to your main domain name. Subdomains are created to organize and navigate to different sections of your website. You can create multiple subdomains or child domains on your main domain.

How do I keep an image from a subdomain in Wordpress?

To create a subdomain, log in to your cPanel or other control panel that your host provides and enter the Subdomains section. Under Create a Subdomain, enter the name of your subdomain. You can choose any name that makes sense. For example, you can use img, images, media or anything of your choice.

Can you host a website on a subdomain?

These are just a few common examples, but you can use a subdomain for virtually any structure you want to introduce to your website. You could theoretically host every page on your website on a different subdomain, like contact.example.com for your contact page, about.example.com for your about page, etc.


2 Answers

A couple advantages to it:

  • A separate domain prevents your domain's cookies from being sent for every image request, where they're not needed. Reduces the bandwidth overhead for each request.
  • Most browsers will only make a certain number of HTTP requests at one time to a particular domain, so serving images and other static content off a second domain potentially doubles the number of HTTP requests at one time.
  • You can conceivably use a different, lighter weight webserver like nginx/lighttpd to serve the static content.

Downsides:

  • Managing it.
  • Two DNS lookups instead of one.
like image 127
ceejayoz Avatar answered Oct 23 '22 19:10

ceejayoz


When a browser is requesting static files like CSS and Javascript, it often limits the number of connections to a given server/sub-domain. Putting static files under a different domain allows more simultaneous downloads.

If set up correctly, the different sub-domain may just be a directory on your webserver. Depends on your config-file-fu.

like image 29
pivotal Avatar answered Oct 23 '22 19:10

pivotal