Helping people with computers... one answer at a time.

There's a minor speed win that busy web sites striving to be as fast as possible might take advantage of that's a little cleaner if you start with www.

In a previous answer you mention that while http://ask-leo.com is the standard way you refer to your site, "knowing now what you didn't know then" you might choose http://www.ask-leo.com - why is that?

Naturally the question above is technically a constructed one, but as I shared my decisions and thought processes with others on how I arrived at "http://ask-leo.com" as my standard and not "http://www.ask-leo.com", this issue came up and I realized that I might have chosen differently had I known. I want to record what went into that thinking.

Warning: this is for website owners, and it gets fairly geeky.

If you don't care about the details then choosing to include "www" for your own site is a fine choice, just be consistent.

On the other hand, if you want to know why it might or might not matter, read on.

If I had to start Ask Leo! over again...

The short version is that there's a minor performance implication that would favor using "www.ask-leo.com" over "ask-leo.com" had I done so from day one.

"The issue comes down to cookies."

If you expect to have lots of traffic some day, "www.yourdomain.com" might be the way to go, as well as placing static resources like images, css files and javascript files on another subdomain like "resources.yourdomain.com".

If you don't expect lots of traffic, then it doesn't matter. Pick with or without www and stick with it.

The issue comes down to cookies.

How cookies work, simplified

A cookie is just some data that a website instructs your browser to save for it. The next time you visit that same web site the cookie is sent along with each request for a resource from that site.

For example, when you visit ask-leo.com one or more cookies may be placed on your machine and associated with "ask-leo.com".

When you then request another resource from ask-leo.com all the cookies that are associated with "ask-leo.com" are sent with your request.

That's, fundamentally, how cookies work. They're just a way for a web site to save some data on your computer that's saved for the next time you visit that site.

Cookies are sent with everything

Cookies are sent with each request your browser makes no mater what you're requesting as long as the domains match.

Let's say I've visited ask-leo.com, and cookies were placed on my machine.

Let's also say that the next page I visit on ask-leo.com has two pictures on it.

  • The browser requests the page, and with that request sends the cookies that left from the previous visit with the request.

  • The browser requests the first picture, and with that request once again sends the cookies.

  • The browser requests the second picture, and with that request sends the cookies yet again.

In most cases cookies are kinda pointless for things like images. (Typically this applies to style sheets, videos, javascript files and perhaps others, but I'll use images as the example.)

And yet we sent up cookies twice for images when we didn't need to. That's additional data sent with each request that we didn't need to send, and additional time spent transmitting that data that we didn't need to spend.

There's a small speed improvement to be had here.

Solution number one

The most common solution to this problem is to simply move the images to a different domain.

Remember, cookies are sent for each request made on domain which previously left cookies. If the pages come from one domain, say "foo.com", and the images are all stored on a different domain, "bar.com", the cookies saved for foo.com won't get sent with the requests for images from bar.com.

Seems fairly simple, and in theory it really is.

Unfortunately, there's a catch.

Why solution number one didn't work for me

My initial approach was to move all of the pictures on Ask Leo! to a different domain - images.ask-leo.com - rather than ask-leo.com.

Different domain, right?

Kind of, but when it comes to cookies not different enough.

Since images.ask-leo.com is a subdomain of ask-leo.com the ask-leo.com cookies are sent anyway. It's a different domain, but apparently the rules that govern how cookies work say that they should be sent in this case.

So even though the cookies were saved for the domain "ask-leo.com", they were also sent with requests for images off of "images.ask-leo.com". No speed improvement there.

Solution number 2: what I could have done from the start

Had I standardized on "www.ask-leo.com" instead of "ask-leo.com" as my default domain name to be used in all references then simply adding "images.ask-leo.com" would have solved the problem.

If my pages had all been "www.ask-leo.com" then all the cookies would be associated with that domain. "images.ask-leo.com" is not a subdomain of "www.ask-leo.com" and is, in fact, a completely different domain than "images.ask-leo.com".

Even when it comes to cookies.

Cookies saved for "www.ask-leo.com" would not have been sent along with requests for images from "images.ask-leo.com".

Solution number 3: what I do today

I ended up moving all my images to a completely different domain - askleomedia.com. Nothing coming from askleomedia.com ever leaves a cookie, and thus all the requests to and responses from are cookie-free.

Pages are fetched from "ask-leo.com" and may leave and include cookies.

Images come from "askleomedia.com" and are cookie-free.

Why I didn't change to www

You might be asking yourself why I didn't change from "ask-leo.com" to "www.ask-leo.com".

Mostly because I'm scared.

All of the search engine engines know my site as "ask-leo.com". If I suddenly change to "www.ask-leo.com", (which can certainly be done with no visitor impact), all of a sudden the site that the search engines know and (hopefully) love - ask-leo.com - will have disappeared. The new site - www.ask-leo.com - could instantly replace it, or it could take months to once again work its way into the search engine's loving embrace.

I can't afford the risk.

Does any of this matter?

For most websites, probably not. The amount of data we're talking about here is pretty small, especially compared to the massive size of so many sites pages.

If your traffic is light and expected to remain so, if you don't rely on search engine results for visitors to find you, or if your site uses no cookies at all, then this doesn't matter.

On the other hand, if you're trying to improve the speed at which your pages are displayed to users (which may be one of the many criteria used in search engine results ranking), and you do use cookies (if you have advertising, analytics, a newsletter signup form or any of a number of other things you almost certainly do), then this is a decision that you might want to consider when you initially set up the domain.

Place static files that need no cookies on a different domain than your site's domain. If your site uses "www." for all references then the different domain can simply be a separate subdomain, otherwise it'll need to be a completely different domain.

Article C4719 - January 21, 2011 « »

Share this article with your friends:

Share this article on Facebook Tweet this article Email a link to this article
Leo Leo A. Notenboom has been playing with computers since he was required to take a programming class in 1976. An 18 year career as a programmer at Microsoft soon followed. After "retiring" in 2001, Leo started Ask Leo! in 2003 as a place for answers to common computer and technical questions. More about Leo.

Not what you needed?

Comments on this entry are closed.

If you have a question, start by using the search box up at the top of the page - there's a very good chance that your question has already been answered on Ask Leo!.

If you don't find your answer, head out to http://askleo.com/ask to ask your question.