• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Does it help to use subdomains for image and javascript hosting?

Lone Wolf

Well-known member
#1
My forum got a 0 score for subdomain usage on a speed test website so I was reading a few guides to see what it was all about.

Does it help speed up the website if you load different types of contents from different subdomains? For example...

images.mydomain.com (for attachments and server hosted images)
scripts.mydomain.com (for javascript, etc)

Does this work and what other subdomains would be useful because the advice was for 4 to 5 subdomains?

Would be great to hear from anyone who has experience with this.
 

Mr. Goodie2Shoes

Well-known member
#2
Different sub-domains are considered as "different sites" and since there is a limit to number of connection per host by the browser using different sub domains will increase the number of active connections, thus loading the site faster :)
 

Mr. Goodie2Shoes

Well-known member
#5
Does this involve moving directories around or can I leave the setup as it is and just call the directory via the subdomain?
Not needed, you can just point the sub-domain's document root to /home/username/public_html/data, update the config.php file to the 'data' URI to the new sub-domain and you are good to go! :D
PHP:
$config['externalDataUrl'] = 'http://data.domain.com';
 

thedude

Well-known member
#6
Does it help speed up the website if you load different types of contents from different subdomains? For example...
With SPDY and the recently finalized HTTP2 standard, no, multiple domains won't improve speed, if they're all pointing to the same physical server.

All major web servers (apache, litespeed, nginx, etc) will have support for HTTP2 in the very near future so it may not be worth your while to shard your domains (make multiple asset domains) at this point.
 

Lone Wolf

Well-known member
#7
With SPDY and the recently finalized HTTP2 standard, no, multiple domains won't improve speed, if they're all pointing to the same physical server.

All major web servers (apache, litespeed, nginx, etc) will have support for HTTP2 in the very near future so it may not be worth your while to shard your domains (make multiple asset domains) at this point.
We wont be updating to HTTP2 + SPDY for a few weeks yet. UNtil we do that, wouldnt the subdomains thing help out
 

thedude

Well-known member
#8
We wont be updating to HTTP2 + SPDY for a few weeks yet. UNtil we do that, wouldnt the subdomains thing help out
If the only purpose is to score better on that site analysis test, I wouldn't bother. Since you're switching in the near future to the newer protocols, it'll very much be a waste of time.

On the other hand, if you want to offload your static assets (images, javascript, etc) to a content distribution network such as CloudFlare, Amazon CloudFront, or MaxCDN, then I would recommend creating a new domain, or using a subdomain of your existing domain for that. You'll only need one domain (or subdomain) for it, since CloudFlare currently uses SPDY, and all the major CDN's will use HTTP2 in the near future. So instead of images.mydomain.com AND js.mydomain.com, you could just create static.mydomain.com. However the better alternative would be to create an entirely new domain just for the assets so it's cookieless.

Here's a good guide for using XF with a CDN. The key parts are under the heading "How To Add Your CDN in Xenforo Settings"

We use CloudFlare with a completely separate domain than our website, and they're able to cache on average > 87% of our static data requests (javascript, etc), so our server can use its resources for generating the php pages for the visitors.
 
Last edited:

Lone Wolf

Well-known member
#9
We use CloudFlare with a completely separate domain than our website, and you can see below how much bandwidth our server doesn't have to worry about serving. CloudFlare cached 87% of the static data requests (javascript, etc), so our server can use its resources for generating the php pages for the visitors.
That looks really good but my site isn't all that busy, I just want to speed it up and optimise it as much as possible without spending any more as my budget is stretched with the VPS already.

How much would a CDN charge per month for a setup like that?
 

Mr. Goodie2Shoes

Well-known member
#17
According to that there are no mobile optimisations as part of the free package. I want to speed up the mobile site more than the desktop, wouldnt it be better to do it as a subdomian in that case?
Not really... I think the optimizations include compressed images and such which wont help even with sub-domains.
 

Lone Wolf

Well-known member
#18
@Mr. Goodie2Shoes @thedude

Thanks for your help guys. I'm planning to talk to my server guys and go ahead with using CloudFare to CDN my subdomains. Is this ok...

images.mydomain.com
js.mydomain.com
styles.mydomain.com
data.mydomain.com

I'm just tying to get a few concurrent downloads per page to ensure a quicker load speed.