We test our webpages on speed testing tools to find out its overall performance score and possible errors. These tools let you know what things are fine on your page and where you need to improve to make the page perform better in terms of loading speed and SEO.

Popular tools like GTmetrix, Pingdom, Page-insight, Bitcatcha, etc first scan your page and then measure to provide a score based on the page speed, the number of elements it contains, requests made by the page to the server to retrieve those elements per unit time.

You will also receive the recommendations per page that basically says where you need to put the work to take your page to the next level. Here is an example report provided by GTmetrix for a particular webpage.

gtmatrix-report-view
GTmetrix recently updated their UI and it’s cool

The GTmatrix grade in the test report is an assessment of the overall performance of your webpage that reflects how fast it loads for the user and it’s built quality to deliver recommended performance.

It also fats information from Google Lighthouse and displays assessment with custom GTMatrix edit.

gtmetrix-grade

On the other tab, you will see the web-vitals report which is a metric that represents whether your page is delivering the kind of user experience recommended by Google.

Under web vital, you will notice LCP which is the calculation of time taken for loading the largest element on a page to appear for a visitor. According to GTmatrix LCP of a page should remain under 1.2 seconds.

Other important measures such as total blocking time (TBT) I will tell you how much time is blocked by the script on your page during loading. The lower the value the better is your score.

web-vitals-of-gtmetrix

Below these scorecards, you will get the top issues and warnings detected by GTmatrix and their related recommendation to resolve them. These issues are organized in a hierarchy which you can follow step by step and improve your page performance.

As you can see in the image above, leverage browser caching is a common problem for most websites. Another most common warning that appears in GTmetrix is to configure cookie-free domains.

If you are also getting serve scaled images warning on GTmetrix, follow this tutorial.

In this post, we will particularly talk about what is a cookie-free domain? Why should you use cookie-free domains? and how to configure cookie-free domains?

Before you start; remember, it’s good to use cookies for security, analytics and other features, however if you notice the cookie size which is of few bytes won’t bring great impact on the performance.

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 during browsing. These cookies use to record and hold information on a user’s activity on a webpage and later use them whenever necessary.

A cookie-free domain is a domain that does not send a command to the visitor’s browser to store cookies from the website. Our website has some static content such as image, JavaScript, and CSS files.

These contents don’t change so often. That’s why they don’t need to be accompanied by cookies because there is no user interaction with these resources.

So by configuring a domain that doesn’t set cookies, you can decrease the size of the total request made by the visitor’s browser to our server and network traffic, while trying to download page resources.

Serve static content from a different domain to avoid unnecessary cookie traffic.

- GTmetrix

The concept behind this approach is to reduce server latency by reducing the number of requests which can impact a little on your individual page performance as well as the primary domain.

Now you know why you should use a cookieless domain, it’s time to plan how would you set up a cookieless site! It might look difficult but it’s not when you understand the flow of the mechanism.

With that being said, let’s get into the tutorial part and try and get your cookie free domain

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 one.

In this way of setting up a cookie-free domain, you will take a separate domain name to host a cookie-less website. It will host all the static contents without any cookie command to the browsers.

So, first of all, you have to register for a top-level domain, if you already have a domain name then skip to the next step. Alternatively, you can create a subdomain to avoid acquiring a domain.

In the case of a sub-domain, use a static prefix for better naming convention and make it easily understandable. For example: www.static.wpblogging.in.

Remember If you use your root domain without the www version, like wpblogging.in then using the subdomain as the cookieless domain might not work.

Again, if you are using Adsense advertisements then a 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

Now follow these steps;

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

To be more specific, after setting up the cookieless domain, use your .htaccess file to configure your webserver to serve static contents without cookies.

You have to keep the .htaccess file in the root folder of your domain. If you don’t know how to find and edit the .htaccess file check this article. Inside the file, you have to add these lines given below, _

# Use Mod_deflate to compress static files SetOutputFilter DEFLATE 
# Speed up caching FileETag MTime Size 
# Expires ExpiresActive On ExpiresDefault "access plus 366 days" 
# Future Expires Headers Header set Expires "Sat, 27 Dec 2019 23:59:59 GMT"

After this, you need to upload all of your static contents (components of your site that don’t change) to the new static sub-domain (or domain).

These contents include CSS, ICOs, Javascript, text, and image files. This way you can create a standalone cookieless domain from where static contents of your original website will be served.

2. Use a CDN provider to ignore cookies

Another good way to solve the cookie-free domain is by using a CDN provider. 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.

Each CDN has different features and functions, some may suit your need while others might not benefit you in solving the warning to use cookie-free domains. And if you are currently using Cloudflare CDN then you may need to disable it because you can’t just allow cookie-free domains in Cloudflare, unless you upgrade to the enterprise plan.

They inject a cookie called “__cfduid“.  Due to Cloudflare’s reverse proxy strategy, cookies are sent on static files too, which are unnecessary.

According to Cloudflare;

Enterprise customers may request to disable the _cfduid cookie by contacting Cloudflare Support, but Cloudflare’s ability to detect and mitigate the impact of malicious visitors to a Customer’s website will be significantly impacted. While some speed recommendations suggest eliminating cookies for static resources, the performance implications are minimal.

- Cloudflare

If you use Cloudflare with a caching plugin, you can change it to another CDN provider to solve the problem.

KeyCDN is a great alternative if you are looking for hosting a cookie-free site. You can deploy keyCDN to your WordPress site with a CDN activator plugin. Just follow the steps below.

  • Go to the official KeyCDN website and create an account. They charge about 0.04$/GB of traffic data after one month free trial period ends. Test their service and if you feel better then go for a premium account.
  • Then install the CDN enabler plugin on your website from the WordPress repository.
  • Create a new Pull-Zone inside the keyCDN dashboard and save it.
create-pull-zone-for-cookie-free-domains-2
  • Copy the CDN URL and paste inside your WordPress plugin.
copy-pull-zone-URL-cookie-free-domain-2
paste-url-inside-CDN-enabler-Cookie-free Domains
  • 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 the cookie-less domain warning on your website test result.

3. Re-configure your WordPress site

In this method, you will create a subdomain from where you will deliver your static file. Then you need to point your subdomain to the /wp-content directory of your current WordPress installation.

Those who use cPanel, you will need to update the document root field from public_html/static to public_html/wp-content.

(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)

Now edit your WP-config to reflect the following,

define("WP_CONTENT_URL", "https://static.domain.com"); define("COOKIE_DOMAIN", "www.yourdomain.com"); 

Point to note: Replace your domain URL and domain name inside the code mentioned above. Example: https://static.google.com

Now, run the following command in your SQL database to ensure all post URLs are directed to the new subdomain:

UPDATE wp_posts SET post_content = REPLACE(post_content,'www.yourwebsite.com/wp-content/','static.yourwebsite.com/')

One more alternative 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 menu. Configure the settings under the “Deploy static website” tab. Check out the image below.

use-cookie-free-domains-wp2static-configuration-1024x423

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 shouldn’t appear inside the report.

5. Try it with BunnyCDN

As I have mentioned above, CDN will help you serve cookieless content on-page, one great example is BunnyCDN.

BunnyCDN will make your task even easier as toggling a button. On the cache control panel, you need to activate disable cookies and you can see an immediate impact on your site.

BunnyCDN

Though, serving a cookie-free domain won’t improve your site performance by a lot still you will be able to achieve a better score on page testing tools like Pingdom & GTmetrix.

Need help with getting stuff done? Try Fiverr! You can find content writers for your website at a reasonable rate.

Similar articles:

How to Configure Async Javascript Plugin Settings?

Top 10 Best Website Benchmarking Tools

How Important is Your Website Load Time?