How To Setup Cookie-Free Domains Properly [Updated In 2021]
We all do a website speed test to know our website loading speed and performance score. There are popular tools available like GTmetrix, Pingdom, Page-insight, Bitcatcha, etc. These tools scan our website and point out which things are good and where changes are required.
If you are wanting to use WP Rocket to setup a cookie free domain checkout this tutorial.
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! “
Additional reading: Best Pay Per Month Web Hosting In 2019 For WordPress Website
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 which does not send a command to 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 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.
You can watch the video to understand it visually.
Additional Resources: How To Make Money Online Through Affiliate Marketing Program In 2019
How to setup or use cookie-free domains
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 a 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.
Tip: Before getting started, I think it’s important to let you know that you can try our website optimization service if you don’t want to go through all these optimization processes. This service is designed to help people optimize their sites for upcoming core web vital updates and a lot of people already enrolled their sites into it. The service’s price point is very friendly as well, plus I will provide you an additional $50 off coupon, which will make things much easier on your side – SPEEDY50.
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 skip to the next step but if you don’t have yet buy a new one. You can also create a sub-domain in case 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. For example: “www.static.rankwp.in“
*Remember: If you use your root domain without www version, like rankwordpress.in then using the subdomain as the cookieless domain will not work.
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.
Read this tutorial: set up a cookie-free domain for both WordPress and non-WordPress website.
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.
# 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 2018 23:59:59 GMT"
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 static content of your original website will be served.
2. 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 keyCDN to your WordPress site by using a plugin. Just follow the steps below.
- Go to their website KeyCDN and 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 keyCDN dashboard and save it.
- Copy the CDN URL and paste inside your WordPress plugin.
- 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");
* don’t forget to replace your domain URL and domain name inside the code. Example: https://static.google.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.
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.
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.
Thank you. It looks like an amazing list of alternatives. Do you think it will only remove the error message the GTMetrix tool or it will have an impact on the loading speed of the site as well?
Currently trying out the method that uses the plugin WP2Static, seems to have shaved off a few seconds. It’s currently crawling so I will see how I look when it gets done.
Thank you.