Cookies are small pieces of data that are sent from a website and stored in your browser.
Each time you browse the same site, the browser sends the cookie to the website’s server thus providing it with the information that was set in the last request.
When you use cookie-free domains you are able to separate the content that doesn’t require cookies from the content that does. This helps improve your site’s performance by eliminating unneeded network traffic.
To enable a cookie free domain for a WordPress site, you need to follow the below methods.
1. Create a subdomain, such as cookiefree.yourwebsite.com, which is where you will deliver all your static files from.
2. Point your new subdomain to the /wp-content directory of your WordPress installation. For cPanel users, you will need to update the document root field from public_html/cookie free to public_html/wp-content like the screenshot below.
3. Edit your wp-config.php file to reflect the following:
define("WP_CONTENT_URL", "http://cookiefree.yourwebsite.com"); define("COOKIE_DOMAIN", "www.yourwebsite.com");
4. Run the following command in your SQL database, this will ensure all post URLs are directed to the new subdomain:
UPDATE wp_posts SET post_content = REPLACE(post_content,'www.yourwebsite.com/wp-content/','cookiefree.yourwebsite.com/')
Now that your cookie domain and static content subdomain are set, you can begin delivering static content without the server setting an unnecessary cookie for static assets.
That’s it, Enjoy!