How to Set Up a Cookieless Domain in Linux

Share It!

First, let’s discuss what is static content. There are few files which never change as per request, files like images, CSS, js, videos etc. In other words, files that are not used to build dynamic content like PHP, aps(x), JSP. The benefits to removing the cookies from static content are it will reduce the total size of requests made to build the web pages and makes them load faster. Removing the cookies from the request header is one of the performance settings needed to speed up your site. Remember that you still need to cache and compress some files.

Cookieless Domain

Today we are trying to help you to serve static content like images, CSS, and javascript from what is known as a “Cookieless Domain.”

Cookieless Configuration

First edit or create a .htaccess file on the documentroot of you domain which you want to make cookieless domain. This method will work only with Apache web servers. Add below code in .htaccess file.

# vim /var/www/html/techoism/.htaccess
# 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 2018 23:59:59 GMT"
</filesmatch>

Once you have your cookieless domain set, simply add your static content such as javascript, 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 this article will help you to setup the cookieless domain.

Enjoy it!

Leave a Reply

Your email address will not be published.