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.
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! ”
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.
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.
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.
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 WordPress site. So we will discuss these methods one by and so on.
Here, we I will mention the tested methods which worked well for my blog.
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.rankwordpress.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 to set up a cookie-free domain for both WordPress and non-WordPress website.
- Create a sub-domain using (static) prefix
- Create a CNAME record to your new sub-domain
- Perform a website speed test using any of the listed tools above
- 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"
This way you can create a cookieless domain from where static content of your original website will be served.
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.
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", "http://static.domain.com"); define("COOKIE_DOMAIN", "domain.com");
* don’t forget to replace your domain URL and domain name inside the code. Example: http://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 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.
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.