-4

I know that www actually a subdomain of the main domain. But, I have to deal with some urls where, http://example.com/ refers to the same location as http://www.example.com/.

So, when the two links refers to the same location and we are linking the sites with hyperlink <a href="http://example.com/">, is there a performance difference for using http://example.com/ vs http://www.example.com/? If so, which one is better to use in hyperlinks and why?

2 Answers2

4
  • There's no technical difference. They're both just different names. Choose the one you prefer. Historically example.com did not resolve to anything "visible" and was only used for, for example, email delivery; the world wide web server was explicitly exposed on a www. subdomain. In practise this doesn't matter at all today.
  • You should ensure that you always only use one or the other. Don't mix and match. You should ensure that your server only answers to one or the other domain, not to both with the same content. For SEO purposes you should have one canonical URL for your content, not several URLs which serve identical content. Have your server redirect one to the other, or outright ignore requests to anything but the canonical URL.
  • Since "doubleyou-doubleyou-doubleyou" is so terribly ingrained in people's minds, it's advisable to support a www. subdomain, even if you just use it to redirect to your canonical domain.
  • Technically the www. subdomain may incur an additional DNS lookup and be ever so slightly slower to resolve. But in practice this doesn't matter one bit, since DNS is heavily cached and both will resolve equally fast in practice.
deceze
  • 510,633
  • 85
  • 743
  • 889
  • Isn't there a difference in terms of cookie-handling and how non-www cookies are visible to other subdomains compared to www cookies? – Uwe Keim Jan 08 '16 at 09:41
  • 1
    That has nothing to do with `www.` in particular. If you set cookies, you can decide whether they're valid only for the current domain, or the current domain and all its subdomains. So, if you set a cookie on `example.com` for `.example.com`, then this cookie is also visible from `www.example.com`. However, the other way around doesn't work. However, this is all completely irrelevant since you should use only one canonical domain to begin with. If you're planning some large-scale infrastructure with several sub domains which should all share cookies (or not), this factors into it obviously. – deceze Jan 08 '16 at 09:44
0

There is no performance difference, it could be in a sense that sometimes web developers redirect www.example.com to just example.com but there's nothing that you can do about it.

If you're linking to a website you're probably already linking to a redirected link and if you're linking within your own domain you can use relative urls most of the time.

It however has no effect on performance, unless you're worried about the amount of bytes you're sending over the web but that is something that most web developers call premature optimization.

EDIT

At any time you can use the www. prefix or you can leave it out, it's just what you prefer, there is no difference, no extra latency or resolving going on it's just something extra in the URL that has no impact (like a hash url is too except that points to a different part in the page that gets resolved after the request is done).

TL;DR;

You can just use whatever you want, it makes no difference (maybe in the future but nothing yet anyway).

SidOfc
  • 4,552
  • 3
  • 27
  • 50
  • I am not talking about the hyperlinks within my sites. The urls are from different domains. – Tᴀʀᴇǫ Mᴀʜᴍᴏᴏᴅ Jan 08 '16 at 09:03
  • The relative url was just another example @TareqMahmood - it doesn't matter at all if the url has `www.` in front of it or not except for what I said about websites redirecting to a `www.`-less domain but that's not something you control – SidOfc Jan 08 '16 at 09:04
  • So, should I just exclude `www`, when setting the hyperlink? – Tᴀʀᴇǫ Mᴀʜᴍᴏᴏᴅ Jan 08 '16 at 09:05
  • @TareqMahmood I'll clean up my answer a bit for you and future readers and include the something about that last comment you posted, one sec. – SidOfc Jan 08 '16 at 09:05
  • I wonder if there isn't possibly a slight delay at the DNS server level. The order of lookup by the DNS might have an ever so slight marginal impact. We're talking very tiny units of time, and not enough to be noticed by any user or even system, but a million requests to www.mydomain,com compared to a million requests to my domain.com will probably yield a difference). – nspire Jan 08 '16 at 09:10
  • @nspire *maybe* in the case of millions of requests but it has no impact that you should care about when just clicking a link anyway, and I don't think dns handles `www.` links differently but it could be something with parsing the entire url being a tad bit slower but again that is neglible :) – SidOfc Jan 08 '16 at 09:12
  • @nspire, Yes, I was just thinking about that. But which one is real? In cPanel, we put the files inside `public_html` which is the same as `www`, So, I am just confused, which one will take less time? – Tᴀʀᴇǫ Mᴀʜᴍᴏᴏᴅ Jan 08 '16 at 09:15
  • @TareqMahmood It makes no difference as stated in the answer (except for SEO as [amitguptageek](http://stackoverflow.com/a/34673260/2224331) is saying in his answer below) – SidOfc Jan 08 '16 at 09:20
  • @SidneyLiebrand, Isn't it true the redirection takes time? It may be a fraction of millisecond, which may not impact performance. But I just want to use the better option by standard, when I know that both versions are available for the site. – Tᴀʀᴇǫ Mᴀʜᴍᴏᴏᴅ Jan 08 '16 at 09:23