Forum Moderators: phranque

Message Too Old, No Replies

www CNAME or A record?

         

csdude55

5:15 am on Dec 22, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



By default, it looks like WHM/cPanel creates accounts with "www" as a CNAME for the domain without the www; eg, "example.com."

example.com. A 123.45.67.89
www CNAME example.com.


But I see that intoDNS throws a warning that it can't "get any A records for www.example.com".

Google shows all kinds of pages that imply that both methods are common, and the given reason for using a CNAME instead of an A is so that, if you need to change the IP in the future, you only have to change it once instead of twice.

But what's NOT said is whether there's any speed difference?

My sites all automatically redirect to www (a decision I kinda regret now and wish I'd gone the other way, but whatever). It's my understanding that when someone goes to www.example.com, then the server returns the CNAME, then goes to look for the value of the CNAME to find an A record, then goes to the value of the A record (which is the IP address).

Would it be even marginally faster to cut that process in half by changing the CNAME to an A record with an IP?

example.com. A 123.45.67.89
www A 123.45.67.89

robzilla

8:46 am on Dec 22, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It would, yes. I only use CNAME records when the target domain is outside my control, or the IP address is expected to change.

phranque

8:48 am on Dec 22, 2020 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



My sites all automatically redirect to www (a decision I kinda regret now and wish I'd gone the other way, but whatever). It's my understanding that when someone goes to www.example.com, then the server returns the CNAME, then goes to look for the value of the CNAME to find an A record, then goes to the value of the A record (which is the IP address).

the reason to use a subdomain such as www.example.com is so that you can serve cookies to the www subdomain while not sending cookies for other resources such as images which can be on a non-cookied subdomain.
i would imagine the advantages of this far outweigh the slight savings in the single (or none if already cached) domain name resolution required per requested page.

dstiles

10:40 am on Dec 22, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I never use cname. I set up example.com 1.1.1.1 and www example.com 1.1.1.1 and it all works. Changing IPs at a later stage may take a few hours but there is usually an old and new site running at the old and new IPs.

csdude55

5:15 am on Dec 23, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well... I have one small (older) site that uses both www and non-www; a risk of Google seeing the pages as dupes, of course, but it's not important enough of a site to worry about.

But I did a quick speed test, and found that the non-www version loads in an average of 1.04s (an average of five shift+F5 refreshes), while the www version loads in 1.27s! So I changed the www CNAME to an A record, and I'll test it again tomorrow.

In theory, though, it should save around 20-25ms. So nothing mind blowing or anything, but still... a very simple change for a minor bump, and a bunch of minor bumps can add up to something relevant :-)

robzilla

8:10 am on Dec 23, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have one small (older) site that uses both www and non-www; a risk of Google seeing the pages as dupes

They're separate domains, Google's not going to assume they're the same. Unless they provide the same content, in which case you ought to redirect one to the other or use rel=canonical.

found that the non-www version loads in an average of 1.04s (an average of five shift+F5 refreshes), while the www version loads in 1.27s!

That's 230ms (not 20-25ms) and unlikely to be related to the DNS records. DNS lookups are cached by your browser, so you probably won't find it in the waterfall chart after the first request, even if you do a hard refresh. You can't really test your DNS performance this way. No real need too, either, as logic dictates that a direct record will always be faster than an alias CNAME.

csdude55

8:24 am on Dec 23, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well shoot... this might be irrelevant, then. I just saw that the www version is now loading at 997ms with a hard refresh, but that could also be an issue of lower server load or something.

Either way, it's a very simple change that at worst is the same, at best saves some load time :-)

dstiles

9:29 am on Dec 23, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The www and non-www should be handled in the conf file, redirecting the secondary one to the primary. SEs will only see the primary one, although some of the more stupid ones such as G and B will still probe the secondary (and port 80!).

csdude55

8:11 pm on Dec 23, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yeah, I set that up for my important sites (all redirecting to www, which I kinda regret now and wish I'd redirected to non-www). But this test site is actually a local restaurant that I built a 3-page site for in 2005, and they've been out of business for about 10 years! They still own the building, though, so I've kept it up just in case they ever come back.

So it's not a bad page for testing :-)

At 3pm on a Wednesday (just now), I did a hard refresh and it still loaded in 958ms. I now know that this isn't a fair bench test, but it's still notable that it's consistently loading > 300ms faster than before!