11 February 2017

what is cookie less domain

If you are working on reducing your web site page load time, you will read on making use of cookie less domain to serve static assets. In this tutorial post let’s understand what is cookie less domain in detail.

Cookies add extra bandwidth overhead on static assets requests & response, how?

Usually a web site is built using of static assets like images, CSS, java script files & also pages using dynamic content (like .ASPX, etc). Whenever your browser requests a URL, it will get the page content first and then downloads the images, CSS files and java scripts files.

To download the static assets (if not already cached), your browser will send a HTTP requests to domain hosting them. With HTTP requests to each of static files, browser will send cookies stored for the domain. And then website would send back cookies with response to the browser.

However your website would not be using cookies for processing the requests for static assets. So cookies going and coming back with HTTP request and response for such files is an overhead. Avoiding this to and fro, extra bytes for cookies which not required can result in less bytes transfer over wire resulting in faster page load times.

How can we avoid sending cookies with static asset’s HTTP request/response?

  • Let’s host the dynamic content website on a domain. Call it as www.example.com
  • And host static asserts website on a different domain. For example say on www.StaticAssetExample.com
  • Change dynamic content website to refer static files from static content domain.

So while sending HTTP request for static files, browser will not send any cookies, because dynamic content website cookies are on a different domain. And ensure you don’t set any cookies back in the HTTP response for static assets. With this setup of websites, essentially NO cookies are being exchanged between request and response for static assets. Hence the static assets domain now be called as cookie less domain.

Thus using cookies domain bandwidth required for sending and receiving cookies can be saved, which will reduce your websites response times. So your business websites customers will be happy.

Real world cookie less domain example

Browse any popular site and view the network tab for HTTP traffic in Chrome browser – Developer tools. And then go to image tab and view any HTTP request and response for a image. You will usually see no cookies sent in HTTP request and received in HTTP response. They will be using cookies less domain to server static assets for their business.

If we consider popular site amazon.com for example, they are using different domain to serve images. And as shown in the traffic flow below, for a JPG image no cookies are being exchanged on either request or response.

cookie less domain serving website static assets

No comments:

Post a Comment