How To Setup Cookie-Free Domains Properly

By | June 29, 2019

We all do a website speed test to know our website loading speed and performance score. There are popular tools available like GTmetrixPingdomPage-insightBitcatcha, etc. These tools scan our website and point out which things are good and where changes are required.

Here is an example of a report provided by GTmetrix

As you can see, besides the image problem and loading time most of the test was passed by that specific page. To fix the image problem you can apply this trick.

Now if we go to the ‘Yslow‘ tab next to ‘page-speed‘, you may see a warning that says to use cookie-free domains. Check this image below.

If you are getting this problem for the first time then you should know what is a cookie-free domain? Why should you use cookie-free domains? In case you already know about a cookie-free domain then skip to know “How to setup or use cookie-free domains on your WordPress site! “

What are cookies?

An HTTP cookie is a small piece of data sent from a specific webpage or website. These tiny data are stored on the user’s computer by the user’s web browser when he is browsing.

What is a cookie-free domain?

A cookie-free domain is a very simple concept. It’s actually a domain that does not send a command to a visitor’s browser to store cookies from the website. Our website has some static contents such as image, javascript and CSS files. These contents don’t change so often.

That’s why they don’t need to accompanied by cookies, as there is no user interaction with these resources. So by configuring a domain that doesn’t set cookies, we can decrease the size of the total request made by a visitor’s browser to our server, while trying to download page resources.

The concept behind this strategy is to reduce server latency by reducing the number of requests which can impact a little on your website performance.

As you have understood why you should use a cookieless domain, it’s time to know how do we set up one. Setting up a cookie-free domain seems like a hard task but believe me it’s not. All you have to understand the process and do it perfectly.

There are a couple of ways to configure a cookie-free domain. Such as using a separate domain name, set up a CDN and reconfiguring the WordPress site. So we will discuss these methods one by and so on.

Here, I will mention the tested methods which worked well for my blog.

  • Configure a cookie-free domain separately
  • Use a CDN provider to ignore cookies
  • Re-configure your WordPress site
  • Use Cookie-Free Domains – WordPress Plugin

1. Configure a cookie-free domain separately

In this technique, you will create a completely separate domain name for your website. This separate domain is going to host all the static contents without any cookie command to the browsers. So, first of all, you have to register a domain name.

If you already have then skipped to the next step but if you don’t have yet buy a new one. You can also create a sub-domain in case you don’t want to buy a new one. If you prefer to use sub-domain, use a static prefix so people can understand by looking at the name.

Again, if you are using Adsense advertisements then cookieless domain warning will always occur because your sub-domain is a part of your root domain and Adsense set cookies for every sub-domain under one verified domain name.

Steps:

  • Create a sub-domain using (static) prefix
  • Update your root document
  • Update wp-config file
  • Update existing post contents

After creating the cookieless domain, Use your .htaccess file to configure your web server to serve static contents without cookies. Here you have to put that .htacess file into the root folder of your domain. Here’s how to find and edit the .htaccess file once you find the .htaccess file paste the following code there.

Once you’ve set up the cookieless domain now you need to upload all of your static content to the new static sub-domain (or domain). These contents include CSS, ICOs, Javascript, text and image files. This way you can create a cookieless domain from where the static content of your original website will be served.

  1. Use a CDN provider to ignore cookies

Using a CDN provider is another good way to solve the cookie-free domain problem. Most of the CDN has the ability to ignore cookies and strip cookies which helps to completely prevent the browsers from receiving the Cookie response header. Since it’s hard to guess which CDN to use.

Just because every CDN has different features and functions so not every CDN is suitable for you to solve the warning to use cookie-free domains. If you are currently using Cloudflare CDN then you need to disable it to disappear the warning to use cookie-free domains.

The reason is that you can’t disable cookies served through CloudFlare CDN. Moreover, they also include their security cookie in your website header. But if you use CloudFlare with a caching plugin, you can change it to another CDN provider to solve the problem.

KeyCDN is the nicest alternative I have ever used with my websites. You can deploy key CDN to your WordPress site by using a plugin. Just follow the steps below.

  • Go to their website KeyCDNand create an account there. They charge about 0.04$/GB traffic data and you will get one month for a free trial for a new account. Test their service and if you feel better then go for a premium account. ( You don’t have to submit your credit details. )
  • Install the CDN enabler plugin from the WordPress repository.
  • Create a new Pull-Zone inside the key CDN dashboard and save it.

create-pull-zone-in-key cdn

  • Copy the CDN URL and paste inside your WordPress plugin.

copy-pull-zone-URL

paste-URL-inside-CDN-enabler

  • Once your setup is done, clear your website cache and wait a little time to take the effect.

On completion of your set up, you should see the improvement in your website test results on gtmetrix.

3. Re-configure your WordPress site

In this method, you will set up your subdomain’s DNS record as a CNAME pointing to your root domain with the wp-config file. To do that point your subdomain (any) to your /wp-content directory simply by editing your wp-config.php file. Add the following codes into your wp-config file.

define(“WP_CONTENT_URL”, “https://static.domain.com”); define(“COOKIE_DOMAIN”, “domain.com”);

 

4. Use Cookie-Free Domains – WordPress Plugin

One more alternate method is to use a WP plugin called WP2static. You can easily install the plugin from the WordPress repository.

wp2static-plugin

After installing the plugin activate it. Now go to the WP dashboard and select wp2static from the left bar menu. Configure the settings inside the “Deploy static website” tab. See the image below.

wp2static-configuration

Once the export process is done, visit the URL that you have set during the configuration. (https://yourdomain.com/static). Now check that URL in GTmetix. The warning to use cookie-free domains won’t be displayed inside the report.

Final Word

Using these cool tricks you can get around of that annoying cookieless domain warning on gtmetrix or Pingdom. In the comment box please share is this article helpful for you or not. Also, do share with your friends if these tricks work well with you.

Leave a Reply

Your email address will not be published. Required fields are marked *