Portal Home Knowledgebase 3. WordPress How to Create a Cookie-Free Domain for WordPress

How to Create a Cookie-Free Domain for WordPress Print

  • 0

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 interactions. While cookies allow websites to remember users, they do not make browsers forget a page; instead, they can increase latency and generate unnecessary network traffic. A website that loads quickly has a significant impact on user experience, traffic, and SEO.

For example, e-commerce websites use cookies to track and store purchase history and shopping cart items. When you revisit the site, it can recommend products based on your previous activity. Tools like GTmetrix, Pingdom, or PageSpeed can help check your website speed and offer recommendations on utilizing a cookie-free domain for serving static content.

What Is a Cookie-Free Domain?

A cookie-free domain allows you to separate content that requires cookies from content that does not, ensuring that your site only serves cookies when necessary. By not sending requests to store cookies, a cookie-free domain reduces the number of requests sent to the server, improving website performance and eliminating unnecessary traffic.

How to Set Up a Cookie-Free Domain in WordPress

There are several methods to set up a cookie-free domain. Follow these steps to implement a cookie-free domain on your WordPress website:

1. Create a Subdomain

A cookie-free subdomain is necessary to deliver static content. Using the main domain will cause cookies to be set on all subdomains.

  • Log into cPanel and select Subdomains.

  • Create a new subdomain (e.g., website.testingsite.com).

  • Point the subdomain to the WordPress wp-content directory in the document root field.

  • Navigate to the File Manager in cPanel and add the following code to your wp-config.php file:

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

    (Replace the links with your webpage's URLs.)

  • Locate your WordPress database in your wp-config.php file.

  • Go to phpMyAdmin -> SQL and redirect all posts to the new domain by executing the following command:

    UPDATE wp_posts SET post_content = REPLACE(post_content, 'www.testingsite.com/wp-content/', 'website.testingsite.com/');

Now, the subdomain website.testingsite.com will deliver all static content without cookies.

2. Set Up a Content Delivery Network (CDN)

Using a CDN like KeyCDN or Cloudflare can also help.

  • Enable the KeyCDN cache cookies settings, which allows users to ignore all cookies, making the website load faster and eliminating cookie-free errors.
  • Create an account on the KeyCDN website (you can try out a free trial or upgrade to a premium account).
  • Install the CDN Enabler plugin from the WordPress repository.
  • In the KeyCDN dashboard, create a new Pull Zone and save it.
  • Copy and paste the CDN URL into your WordPress plugin.
  • Clear your website cache after completing the setup and wait for the changes to take effect.
  • Recheck the test results on GTmetrix to notice an improvement.

3. Use the WP2Static Plugin

Another method involves using the WP2Static plugin.

  • Log into your WordPress dashboard.
  • Go to Plugins, install the WP2Static plugin, and activate it.
  • Select WP2Static from the left sidebar within the WP dashboard.
  • Configure the settings in the “Deploy Static Website” tab.
  • Once the export process is complete, visit the URL set during configuration (e.g., https://testingsite.com/website). The warning about using cookie-free domains will no longer appear in the GTmetrix report.

Advantages of Using Cookie-Free Domains

Using cookie-free domains offers several benefits for your website, including:

  • Reducing unnecessary cookie traffic on the server by serving static content from a different domain.
  • Improving website performance and increasing loading speed, especially for static content, since cookie-free domains do not require users' browsers to store cookies.

Cookie-free domains are a vital part of website optimization efforts. We hope you’ve learned how to set up a cookie-free domain on WordPress to enhance your traffic, SEO, and user experience.


Was this answer helpful?

« Back