How to Set Up a Cookieless Domain

CookielessLately I have been really into helping people speed up and optimize their websites for speed. So today I figured that I would share one of the speed up techniques, which is to serve static content like images, css, and javascript from what is known as a “Cookieless Domain.”

What is a cookieless domain?
The concept and the setup for a cookieless domain are both fairly easy.

Excerpt from Google’s article – Minimize request overhead

Overview
Serving static resources from a cookieless domain reduces the total size of requests made for a page.

Details
Static content, such as images, JS and CSS files, don’t need to be accompanied by cookies, as there is no user interaction with these resources. You can decrease request latency by serving static resources from a domain that doesn’t serve cookies. This technique is especially useful for pages referencing large volumes of rarely cached static content, such as frequently changing image thumbnails, or infrequently accessed image archives. We recommend this technique for any page that serves more than 5 static resources. (For pages that serve fewer resources than this, it’s not worth the cost of setting up an extra domain.)

For the sake of this tutorial, I will assume that this is a brand new domain that is solely for serving static content for another (or several other) domain(s).

To set up a cookieless domain using the Apache web server, edit or create a .htaccess file on the root of your cookieless domain. For example: your-domain.com/.htaccess

Adding the following Apache directives will get your cookieless domain up and running:

# Use Mod_deflate to compress static files
<ifmodule mod_deflate.c>
<filesmatch ".(js|css|ico|txt|htm|html|php)$">
SetOutputFilter DEFLATE
</filesmatch>
</ifmodule>

# Speed up caching
FileETag MTime Size

# Expires
ExpiresActive On
ExpiresDefault "access plus 366 days"

# Future Expires Headers
<filesmatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Sat, 27 Dec 2014 23:59:59 GMT"
</filesmatch>

Once you have your cookieless domain set, simply add your static content (javascipt, css, ico files, text files, and image files) and have the links from your main site point to the correct path on your cookieless domain. You will see a speed improvement instantly.

I hope that this article gets you on your way to serving up your website much faster. I would love to hear your feedback so please leave a comment below. Thanks for stopping by.

Please note that I am still offering a service to Speed Up and Optimize your Website, so please take a look if you are interested.

Tweet ThisTweet This