86

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
  • 16,461
  • 3
  • 32
  • 63
Andreas Bonini
  • 2,605
  • 25
  • 23

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
28

If you are going to use www.example.com, you should make example.com a permanent re-direct to www.example.com.

The www sub domain, in some cases, is actually a completely different server than the parent TLD. While most search engines are smart enough to figure that out, its still good practice to place the re-direct.

I'm the complete reverse of that, www.example.com is a permanent redirect to example.com, because I prefer using the shorter canonical URL. It also make sense to me that I can expect a HTTP request to example.com will yield a web page, or a redirect to whatever subdomain is dealing with HTTP requests.

Additionally, you want people linking to your site using the canonical URL, which is the one they pick out of their browser toolbar. The re-direct on the one that is NOT your canonical URL helps ensure consistency in that regard.

Simon Hayter
  • 33,097
  • 7
  • 60
  • 119
Tim Post
  • 6,586
  • 39
  • 46
24

Including the www subdomain seems to boil down to two conditions:

  1. Cookies - Will setting cookies at *.example.com cause me grief (incur more traffic) because the cookies will be sent with every request, regardless of subdomain. In this case I would opt to use the www since it gives me the choice of setting cookies at *.example.com if I need it (ex. authenticated user cookie), or www.example.com to reduce traffic to my other subdomains.

  2. Aesthetic - Do I care a lot about how the domain looks? If I really hate the www but am worried about the cookie traffic, I could alleviate the problem by hosting my static content on a whole new domain such as static-example.com which would remain cookie free.

Simon Hayter
  • 33,097
  • 7
  • 60
  • 119
chatche
  • 568
  • 4
  • 8
18

This is a minor consideration but one that is relevant for commercial sites. There is an expectation from non-technical users that a website starts with www so when they don't see that they might not think of a domain as a website.

Whilst it may seem silly to those of us that know how things work I have come across this attitude frequently with family, friends and non-technical colleagues and these people are likely to represent the vast majority of your customers.

Additionally, a lot of software such as email, world processors, social networking clients & co will automatically recognise a domain name starting with www as a hyperlink and make it active - with a naked, or non-www, domain you will need to add the http:// for the software to make it active. Being able to click a link instead of having to copy-paste into a browser could make the difference between a customer visiting your site or going to your competitor.

Simon Hayter
  • 33,097
  • 7
  • 60
  • 119
Colonel Sponsz
  • 481
  • 2
  • 7
9

There doesn't seem to be any concrete reasons for using one over the other as far as search results or other desired outcomes. My personal preference is no-www, due to length.

The most important thing is to make sure you redirect to your preferred domain, and remember to set your preferred domain in Google Search Console (Google Webmaster Tools).

Simon Hayter
  • 33,097
  • 7
  • 60
  • 119
Travis Northcutt
  • 1,576
  • 2
  • 16
  • 27
4

Without repeating the valid answers above regarding cookies, aesthetics, non-technical users expecting the www subdomain etc...

Another reason I tend to favour the www. subdomain approach for the main site is for local development. I use local. for my local test server. I always expect the site to be accessed via a subdomain and can easily distinguish between the test and live sites if required. Cookies can be kept separate from the local and live sites.

  • www.example.com Live site
  • local.example.com Local test server

Using a subdomain for the test server also allows easy testing from a mobile device, since the subdomain can be defined in the public DNS that points to a local test server (local IP). Only when the mobile device is on the local WiFi network will it be able to access the local test server. (Make sure that mobile browser optimisations are disabled when connecting locally, otherwise the remote optimisation server will also try to access your local server and fail.)

MrWhite
  • 43,224
  • 4
  • 50
  • 90
2

Yes, always use www instead of a naked domain. Although Heroku is somewhat specialized, the kind of routing fabric they've built is likely going to become more common as people deploy websites across clusters of machines. Naked domains are just much less flexible than www because they require an A instead of a CNAME record. See https://devcenter.heroku.com/articles/avoiding-naked-domains-dns-arecords.

Although you might not think so today, every site on the web should and hopefully soon will be using SSL all the time. That's because security is always better than no security, and the costs of SSL are already only ~1% additional CPU (see http://www.imperialviolet.org/2010/06/25/overclocking-ssl.html). You should get your SSL certificate for www as well.

Zistoloen
  • 10,056
  • 6
  • 36
  • 59
Dan Kohn
  • 121
  • 2
0

My SEO people tell me Google doesn't like naked domains. A symptom of this is that if you try to redirect your myblog.blogspot.com blog to example.com/blog, you will get an error that says Blogs cannot be hosted at naked domains.

Simon Hayter
  • 33,097
  • 7
  • 60
  • 119