Why use Cookieless Domain?

What is a cookieless domain? A cookieless domain is a domain like any other. It is used to serve assets that will not use cookies. It is common to serve images, styles, and scripts from a cookieless domain.

Setting up a cookieless domain is simple. For a site located at http://www.mydomain.com one might consider registering http://www.mydomainassets.com as a cookieless domain. The name of the new domain is not important. The new cookieless domain may be configured to resolve to the same place as the original domain. All of the static files that will not use cookies may then be served from the new cookieless domain by simply changing the source location of that asset.

The value of a cookieless domain may seem small. All of the cookies for a single site are typically less than 10 kilobytes combined. So why go through the work for such a small gain? Because the cookies are sent with every request for every asset. A quick look at popular online news outlets showed an average of 150 requests were made to load the home page. One of the sites, http://msnbc.com, made 265 asset requests in order to load the main page. If 10 kilobytes of cookies were sent with every one of those requests, user’s browsers would be uploading more than 2.5 megabytes of cookies to request assets that would never use those cookies.

Uploading data that will never be used is particularly bad because client requests are not compressed like client responses. Server responses can be compressed to an average 25% of their original size. And many users have asymmetrical internet connections that provide download speeds that are up to 20 times greater than upload speeds. When these circumstances are stacked, 150 kilobyes of upload can take longer than 5 megabytes of response data.

The HTML 1.1 specification limits the number of connections that a browser can establish to a single domain to two connections. Most current browsers disregard this limit and allow for between four and eight connections per domain. Cookieless domains allow browsers to download twice the number of assets simultaneously by adding the extra domain.

Its cheap, easy, and improves the site performance. Win, win win.

Advertisements

About tvalletta

I am just a guy interested in JavaScript, the Internet, Mobile, etc. I have four kids and a beautiful wife. I am an architect at the LDS Church.
This entry was posted in Uncategorized. Bookmark the permalink.

4 Responses to Why use Cookieless Domain?

  1. Joseph Scott says:

    Agreed, cookieless domains are great for content that doesn’t vary based on user/cookie. The request/response weight of a 10KB cookie gets really out of balance when an item has been cached and the server provides a ‘304 Not Modified’ reply.

    It is nice to see edge.ldscdn.org being used for static resources on lds.org, though some of the expiration settings are fairly small. Would be nice to see more of them cached for days instead of hours, or even minutes in some cases.

  2. tvalletta says:

    I agree. A better caching strategy would compliment some of our other site performance initiatives. I would like to see longer expiration settings with a strategy to provide new names for modified files. Perhaps we will need to mature a bit before we are ready for it. Thanks for commenting Joseph!

  3. spudgibb says:

    You could also just use a subdomain such as assets.mydomain.com

    • tvalletta says:

      Yes. You could just use a subdomain. But if you already have top level domain cookies, they will be passed along to the subdomain. Often its easier to drop your $10/year for the new domain.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s