When a browser makes a request for static files on your page such as an image, CSS file etc there is no need for it to add cookies with it, which results in sending additional traffic to the server. And additional traffic means more waiting time for the response by the server.
You can try these steps if you think your server response time is not good.
So the advantage of setting up a cookieless domain is that you can separate the content that doesn’t require cookies from the content that requires it. Using the cookieless domain will deduct unnecessary network traffic and eventually increase the server response time + the page performance.
How to setup a cookieless domain for WordPress site
There are couple of ways to set up a cookieless domain. You can read all the procedures in this page. However, in this article, I will mention how to set it up manually for WordPress website.
Before starting the process one thing you need to remember that if you set cookies on the top level domain ( yourdomain.com) all the subdomains will also include the cookies in them. Because, as it sets on the primary domain its childs are going to have the DNA for sure. So in this case, you are recommended to use a separate domain to deliver static content. It’s a better idea if you register a new domain and configure the web server to serve static resources from the new address. You will completely prevent any cookies to be set in the new domain.
Instead, you can also set two different domains. One which includes cookies and one which doesn’t set cookies. In such a case, will set cookies on a www subdomain (www.yourdomain.com) and separately host your static files from another subdomain like (static.yourdomain.com). This static domain will no longer send cookies with your static files of a page.
Cookieless domain in WordPress.
1. Create a subdomain
Go to your cpanel and create a subdomain like static.yourdomain.com. From this subdomain you will serve or host all the static files.
Go to subdomains > make sure you are on the page ” create subdomain” > place “static” on the subdomain box > let domain box stay in default name > click on create.
2. Point subdomain to wp-content
Now point the newly created subdomain to the “/wp-content” directory of WordPress installation folder.
To do it again go to your subdomains and edit the settings by clicking on the edit icon next to your new static domain.
It will take you to the document root settings where you need to update the root address from “public_html/static” to “public_html/wp-content”.
3. Update your wp-config file
Go to the file manager using cpanel or ftp client and edit the wp-config file. Make sure the following code is available or added inside the file.
**Remember to correct your domain names
4. Direct url to new subdomain
Before taking this step make sure you backup your database in awar to any kind of misconfiguration. Better to practice with demo site before applying in live the version. I do not take any responsibility for further loss of data or website down.
Now you need to run sql query on database table. Go to phpmyadmin > select your wp database > go to SQL tab and paste the following code in the command box.
UPDATE wp_posts SET post_content = REPLACE(post_content,’www.yourwebsite.com/wp-content/’,’static.yourwebsite.com/’)
This will make sure all the post urls are directed to the new subdomain.