CNAME or A Record?


#1

I’m trying to serve images and javascript files from a static domain inorder to make parallel downloads possible. Now I tried creating a static domain with a CNAME entry and I keep getting ‘bad httpd error’. However, when I ping the CNAME entry it resolves to the correct IP address, which is the IP address of the server the website is hosted on. I also verified that this wasn’t a DNS propagation problem by checking it through a couple of proxies. The result in all cases was ‘bad httpd error’.

I tried the same with an A record, and the result was again a ‘bad httpd error’. I really don’t want to go down the route where I’ll have to create ‘sub-domains’. Its not as fast as a DNS entry i.e. CNAME or A record. I’ve done this sort of setup a dozen times on other hosts and it works all the time. What’s going on with Dreamhost?


#2

You will need to set up the (sub)domain in some way or another in the DreamHost Panel — otherwise, the web server has no idea what to do with it. The best way to configure it in this case will probably be as a mirrored domain.


#3

Well, that’s what the CNAME is for. An A record usually requires an IP address as a Value but CNAME can be overlaid on an existing domain. Its the exact same thing you do when you use google as your mail provider, other then changing your MX records. So what’s the difference here? None, whatsoever.

Also, mirrored domains and sub-domains take longer to resolve compare to a CNAME entry. Why? 9/10 times your sub-domain will be hosted on a different IP address in a shared hosting, hence the delay. And a mirrored site will bring back the cookie problem which I’m trying to solve with a static domain. If I’m using a sub-domain or mirrored domain to serve static content, the parallel downloads simply won’t be as efficient.


#4

DreamHost uses name-based virtual hosting. The web server software program - httpd - is configured with a list of virtual host entries. When it receives an HTTP request, it parses out value of the Host header to determine which virtual host the request is for.

The value of the Host header comes from the browser. With a CNAME the browser is going to send the original hostname and not the one specified in the CNAME record. If the original hostname doesn’t match a virtual host entry one could say that is a configuration error for the httpd program.

So what andrewf is telling you to do is to add the domain or subdomain to the panel so that the web server software program configuration is updated. Until you do so there is not going to be any HTTP response except the error document you’re seeing.


#5

[quote=“jackishere, post:3, topic:53177”]
Also, mirrored domains and sub-domains take longer to resolve compare to a CNAME entry. Why? 9/10 times your sub-domain will be hosted on a different IP address in a shared hosting, hence the delay.[/quote]

A mirrored domain is guaranteed to always use the same VirtualHost entry (and hence the same IP address) as the domain it mirrors. DreamHost will automatically create (and update) a new A record for the mirrored domain with the appropriate IP address.

That being said, the amount of time it takes to resolve a DNS entry is minimal (usually a few tens of milliseconds), and, in most cases, it must only happen once or twice in a session. Moreover, the amount of time taken to resolve a CNAME as opposed to an A record is basically the same — so I wouldn’t worry too much about which one is in use. There are much better ways to improve your site’s performance than that.

The cookie problem you’re describing will occur whenever the static content domain is hosted on a subdomain of your primary domain, regardless of how that subdomain is configured. A user’s web browser doesn’t know what the web server is doing behind the scenes; all that it knows is that static.example.com is a subdomain of example.com, so it should send the example.com cookies to it too. If you’re trying to set up a cookieless domain for static content, you will need to set it up at a completely different address. A dreamhosters.com subdomain is a perfect candidate for this task.


#6

Thank you both for taking the time to reply. I really appreciate it.

That may explain it but I’ll have to look into it.

[quote=“andrewf, post:5, topic:53177”]
That being said, the amount of time it takes to resolve a DNS entry is minimal (usually a few tens of milliseconds), and, in most cases, it must only happen once or twice in a session. Moreover, the amount of time taken to resolve a CNAME as opposed to an A record is basically the same — so I wouldn’t worry too much about which one is in use. There are much better ways to improve your site’s performance than that.[/quote]

Just to help out others in similar situations, I’ll try to explain a bit here. The website takes about 1500ms-1700ms to load. Part of the problem is that it makes 31 requests and per second only 20 can be served. Hence the extra 500ms. Only way to combat that is by gzipping or css sprites, which I’m already using with horizontal and vertical groups, or you can use another static domain to serve content to make parallel downloads possible. Now I did a few test runs with sub-domains before I inquired about CNAME entries. In both cases, instead of website loading faster, it started loading slower. It took about 2200ms-2300ms to load with a sub-domain. I verified that by running multiple tests. And the results were similar. So I’m fairly positive that adding a sub-domain, which adds another IP address(90ms-100ms), connection(200ms-500ms) and latency(130ms-300ms), does not help at least in my case. However, it does shave away, the extra 300bytes cookie.

If the cookies are set to use say, www.mydomain.com, and not the top-level domain, mydomain.com. They won’t effect sub-domains. The trick is to add the extra www and with dreamhost its fairly easy to do. But the porblem does come back if you’re using a mirrored domain.