How to Create a Cookie-Free Domain for WordPress

A browser stores cookies for every website visit which provides a personalized browsing experience based on previous visits, it is how websites are remembered. While cookies do not make a browser forget a page, it increases latency and generates unnecessary network traffic. A website that loads fast has a great impact on user experience, traffic, and SEO.

With the use of cookies, an e-commerce website is able to track and store purchase history and shopping cart items, when next you visit the e-commerce store, the site recommends products according to your previous activity. Tools like Gtmetrix, Pingdom or Page Speed check your website speed and give recommendations on how to use the cookieless domain for serving static content.

What Is a Cookie-Free Domain?

Cookie-free domains allows you to separate content that needs a cookie from content that does not, ensuring that your site only serves cookies when it needs to. It does not send the browser a request to store the site’s cookies which will reduce the number of requests sent to the server. Consequently, this will improve your website’s performance eliminating unnecessary traffic.

Find below steps to create and use a cookie-free domain in your WordPress website.

How to Setup a Cookie-Free Domain in WordPress
There are different methods you can use to set up a cookie-free domain. Simply follow these steps to use a cookie-free domain on your WordPress website.

Create a Subdomain

A cookie-free subdomain has to be created to deliver the static content. That’s because using the main domain will make the cookies be set in all your subdomains

  • Log into the cPanel and select Subdomains.
  • Create a new subdomain(website.testingsite.com)
  • Point the subdomain to the WordPress wp-content directory in the document’s root field
  • Navigate to the File Manager in cPanel and add the code below to the wp-config.php file.

define("WP_CONTENT_URL", "http://website.testingsite.com");
define("COOKIE_DOMAIN", "www.testingsite.com");

(Replace the links to reflect your webpage’s URLs).

  • Find your WordPress database in your wp-config.php file
  • Once you have it handy, go to phpMyAdmin -> SQL
  • Redirect all posts to the new domain by running the command below in the SQL database.
    UPDATE wp_posts SET post_content =
    REPLACE(post_content,'www.testingsite.com/wp-content/','website.testingsite.com/')
    The subdomain website.testingsite.com will deliver all static content without cookies.

Set up a Content Delivery Network (KeyCDN and Cloudflare).

Enabling the KeyCDN cache cookies settings allows users to ignore all cookies which make the website load faster and the cookie-free error will be gone.

  • Create an account on KeyCDN website. You can try out a free trial for a new account or upgrade to a premium account
  • Navigate to the WordPress repository and install the CDN enabler plugin
  • Inside the KeyCDN dashboard, create a new Pull-Zone and save.
  • Copy and paste the CDN URL inside your WordPress plugin.
  • Once your setup is completed, clear your website cache and wait for it to take effect.
  • Check the test results on GTmetrix again, you will notice an improvement.

Use WordPress Plugin(WP2static)

You can also use a WP plugin called WP2static.

  • Log into your WordPress dashboard
  • Go to plugins
  • Install the plugin and then activate
  • Select wp2static from the left bar within the WP dashboard
  • Set up the settings inside the “Deploy static website” tab.
  • Once the export process is done, visit the URL that you have set during the configuration. (https://testingsite.com/website). The warning to use cookie-free domains will not display in the GTmetrix report again.

Advantages of Using Cookie-Free Domains

Using cookie-free domains can bring several benefits to your website, including:
Using a different domain to serve static content reduces unnecessary cookie traffic on the server.
Cookie-free domains do not require users’ browsers to store cookies for them which improves website performance and increases loading speed, especially for static content.

Cookie-free domains are an essential part of website optimization efforts, We hope you have learnt how to set up a cookie-free domain on WordPress to improve your traffic, SEO, and user experience.