84

What are the pros and cons of having http://www.example.com/ vs http://example.com/?

For example a problem I'm aware of is that if I use a domain without www I can't set a cookie for the current subdomain only (since there is no subdomain), and the cookies I set will be sent to all subdomains.

Maximillian Laumeister
  • 15,972
  • 3
  • 31
  • 62
Andreas Bonini
  • 2,585
  • 24
  • 23
  • 1
    @John Conde: I think the edit you approved made the question worse.. "My question is fairly simple to complex and want to know the in's and outs of www vs non-www." was edited in, which is broken english and doesn't make sense in any case. – Andreas Bonini Feb 15 '13 at 15:20

8 Answers8

69

Keep in mind though that using www.example.com lets you to set Cookies only on the main site. Using example.com will only allow you to set cookies on *.example.com which includes static.example.com. So every request for any subdomain will include the cookies which slows down the transfer a bit. Using www.example.com will allow you to decide for what part you want to set cookies.

neo
  • 974
  • 7
  • 6
  • 8
    This is one of the big reasons why large websites setup completely separate domains for static content (such as http://sstatic.net for Stack Overflow) so that they have cookie-free domains. More info here: http://developer.yahoo.com/performance/rules.html#cookie_free – Greg Bray Jul 10 '10 at 21:23
  • 11
    yes this is the biggest downside of the "no-www" movement, by far. It is definitely annoying. – Jeff Atwood Jul 11 '10 at 03:32
  • @Jeff: True to an extent, but it can be more beneficial to host static content on a different domain anyway, to increase parallelization. – DisgruntledGoat Jul 12 '10 at 21:04
  • 3
    @DisgruntledGoat: the parallelization is increased also using subdomains! http://developer.yahoo.com/performance/rules.html#split – Marco Demaio Aug 27 '10 at 15:19
  • If you want to create a CNAME that maps the subdomain www. to example.ec2.amazonaws.com. You can't do that with a naked domain. 2. Typing a domain name in the address bar and hitting CTRL + ENTER it automatically enclose the text with http://www. and .com. Having your permanent domain with a www prefix will prevent unnecessary redirection. 3. Typing in example.com under windows start + run will result in an error.
  • – Nick Jun 27 '12 at 18:57
  • 2
    This answer is becoming obsolete now that RFC 6265 is more widely implemented. (It did not exist at the time this answer was written, though.) – Michael Hampton Apr 16 '13 at 03:18