Using Cookie-Free Domains on Drupal

Oct 25, 2010
German Villacreces

When the browser makes requests to the web server, it sends cookie data on the header. On static files like images, stylesheets, javascript files and swf files, the cookie data is not needed so these files should be placed on a separate cookie-free domain. This way we reduce the overhead on the requests.

To make your drupal site work with a cookie-free domain follow these easy three steps:

The first step is to create a domain pointing to the same server. You can use a domain like www.static-yoursite.com.

The second step here is to create another virtual host on apache. We are not going to get into any details of how to do this, but you can follow this guide or any tutorial online. Make sure you use the <Directory> group while creating your new virtual host. The server name and server alias should be the domain name you created in the first step and you should include in the virtual host <Directory> directive group the following lines that disable the cookies:

RequestHeader unset Cookie

Header unset Set-Cookie

The third and final step is to make Drupal point all static files to your separate domain. We do this by installing the CDN Integration module (http://drupal.com/project/cdn). Used to pull static content from another domain or subdomain. Install the module, go to the basic mode settings in Site Configuration > CDN Integration > Basic mode. In this screen input your static domain to the one you just created in this section's first step. In our case, the value we input is http://oshyn-static.com. Save the form, go to the tab called Settings and click on the Enable radio button under Status. Save the form and flush your site's cache.

Now all your static files should point to your separate domain. You can use YSlow to check if all static file requests are being sent without a cookie.


Related Blog Posts


Download the 
Performance Tuning Drupal White Paper.