Mike Rogers Web Developer

Using cookieless domains to improve a website performance

Fast loading times are a really important factor when it comes to website ranking, so it's important to remove as much unnecessary data as possible. A good method to do this is via cookieless domains.

Cookieless domains are (as the name suggests) are domains, in which the user will not send cookies (Which can add quite a few kilobytes to a request). For example, say I want a user to load a static image it would be silly of them to also send me the cookie data. Luckily they are super easy to set up.

Set up a sub-domain

Firstly, set up a subdomain on your website. For example static.yourdomain.com would be suitable, but it's really up to you. Now point the domain to a path where you will keep your static files (Such as images and CSS files). For Full On Design, I set up http://files.fullondesign.co.uk/.

Stop cookies being set site wide

Next, make sure your website does not set website wide cookies. The fastest way to do this is by amending the .htaccess file and adding a CookieDomain Directive. For example:

Alternatively in PHP's setcookie() function, I could just use something like:

The key point to note is that the domain parameter is set to www.fullondesign.co.uk, not .fullondesign.co.uk. Thus the cookies will only be sent when the subdomain is www.fullondesign.co.uk.

Now start linking up to files in that directory and your pretty much done.

Setting up cookieless domains in Wordpress

Wordpress has a few neat built in functions to make this process easier. If you use wordpress pop the following code (just before the "That's all, stop editing! Happy blogging." comment) into your config.php file (amend as required):

You can also change the uploads URL of your Wordpress install to point to your cookieless domain. In the config.php file add the following(amend as required).:

Useful Resources

I've barely touched on the topic of cookieless domains aside from just saying "They making your website load faster", here a two website which go a little more in depth.