Welcome to the Hindi Tutor QA. Create an account or login for asking a question and writing an answer.
Pooja in Domain
Use cookie-free domains: When the browser requests a static image and sends cookies with the request, the server ignores the cookies. These cookies are unnecessary network traffic. To workaround this problem, make sure that static components are requested with cookie-free requests by creating a subdomain and hosting them there.

4 Answers

+1 vote
Tech Guru
selected
 
Best answer

Method 2. 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.

0 votes
Tech Guru

When you use cookie-free domains you are able to separate the content that doesn’t require cookies from the content that does. This helps improve your site’s performance by eliminating unneeded network traffic.

A cookie-free domain is a very simple concept. Exactly referring to a domain that does not send commands to a visitor's browser to store cookies from a website. Our website contains some static content such as image, JavaScript and CSS files. So often this material changes.

How to use or setup Cookie free domains?

As you have understood why you should use the cookless domain, it is time to learn how we set up. Setting up a cookie-free domain is a difficult task but I believe it is not. You just have to understand the process and do it completely.

There are a few ways to configure cookie-free domains. Such as using a different domain name, setting a CDN, and reconfiguring a WordPress site. So we will discuss these methods one by one.

Here, in the next answer I will mention the testing methods that have worked well for my website.

0 votes
Tech Guru
edited

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

Steps:

1. Create a subdomain

Go to your cpanel and create a subdomain like static.yourdomain.com. From this subdomain you will serve or host all the static files.

Go to subdomains > make sure you are on the page ” create subdomain” > place “static” on the subdomain box > let domain box stay in default name > click on create.

2. Point subdomain to wp-content

Now point the newly created subdomain to the “/wp-content” directory of WordPress installation folder.

To do it again go to your subdomains and edit the settings by clicking on the edit icon next to your new static domain.

It will take you to the document root settings where you need to update the root address from “public_html/static” to “public_html/wp-content”.

Update document root

3. Update your wp-config file

Go to the file manager using cpanel or ftp client and edit the wp-config file. Make sure the following code is available or added inside the file.

<?php
define(“WP_CONTENT_URL“,“https://static.yourwebsite.com“);
define(“COOKIE_DOMAIN“,“www.yourwebsite.com“);
?>
  • Remember to correct your domain names accordingly.

4. Direct url to new subdomain

Before taking this step make sure you backup your database in awar to any kind of misconfiguration. Better to practice with demo site before applying in live the version. I do not take any responsibility for further loss of data or website down.

Now you need to run sql query on database table. Go to phpmyadmin > select your wp database > go to SQL tab and paste the following code in the command box.

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

This will make sure all the post urls are directed to the new subdomain.

  • Again make sure that you have corrected the domain details inside the code.

Once you setup everything your cookie domain and static domain are ready for action. And the static domain will start delivering static resources without sending unnecessary cookies traffic.

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.

0 votes
Tech Guru
edited

Method 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

...