Blog Post View


How to setup Cookie-free Domains

As a webmaster, we often run website speed test and learn that use of the cookie-free domains will improve website performance. A cookie-free domain saves network traffic by not sending cookie data with HTTP request.

What are cookies?

An HTTP Cookie is a small piece of data sent from the server with HTTP response, and stored in user's computer as part of web browser data. When users request a specific page, the user's cookie from the last response is sent with the request to the server. Cookies are used to manage a user's session, personalize the user's experience and used for tracking purposes. Cookies store user-specific stateful information and exchanged with server to provide login status, identify user's shopping cart and other stateful information about the user.

Why use cookie-free domains?

In order for a website to perform correctly, some degree of stateful information need to be maintained. However, static resources such as the Javascript, CSS and Images do not require user interaction and hence does not require cookies. A cookie-free domain is a server providing contents with no command to store cookies and thereby improve site's performance. A private CDN can be setup to host static contents and serve as a cookie-free domain.

A webpage is comprised of various components including Javascripts, CSS files, images, and texts. Each component such as the javascript, CSS, and image are individually pulled into a web page causing multiple exchanges of information between the user's browser and the server. Each time a request is made by the user's browser, an HTTP request with cookies are sent to the server and vice versa. By setting up a server without the cookies, each request and response can save processing of cookies and also save network traffic by not sending a small piece of cookie data.

How do you setup a cookie-free domain?

If you set cookies on a second-level domain name such as the iplocation.net, all of the subdomains (i.e. cdn.iplocation.net) will also have to set up to use cookies. To set up a cookie-free domain, you'll have to set cookies on a subdomain such as the "www", (i.e. www.iplocation.net) and host all static resources on a separate subdomain like "cdn". Alternatively, you can register a new second-level domain name and use it to host cookie-free domain.

Cookie-Domain Caveats

Although you may wish to use a cookie-less domain for hosting static contents, in certain circumstances you may not be able to setup a cookie-less subdomain if you're using 3rd-party services like Adsense and Cloudflare. In those cases, you may require to purchase a new domain name or create a cookie-less domain.

  • If you're using cookies in the root domain name (i.e iplocation.net), you won't be able to use subdomain as a cookie-less domain.
  • If you're using Adsense to display banners on your website, setting a cookie-less "sub" domain will not work. Adsense set cookies on every domain under one verified domain name.
  • If you're using CloudFlare as a gate keeper, you won't be able to use a cookie-free domain as CloudFlare sets __cfduid cookie to every response it returns.

Share this post

Comments (0)

    No comment

Leave a comment

All comments are moderated. Spammy and bot submitted comments are deleted. Please submit the comments that are helpful to others, and we'll approve your comments. A comment that includes outbound link will only be approved if the content is relevant to the topic, and has some value to our readers.


Login To Post Comment