How To Make Cookie Free Domain
An HTTP cookie (also known as a web cookie, Internet cookie, browser cookie, or simply cookie) is a small piece of data sent from a website and stored on the user’s computer by the user’s web browser while the user is browsing. Cookies were designed to be a reliable mechanism for websites to remember stateful information (such as items added in the shopping cart in an online store) or to record the user’s browsing activity (including clicking particular buttons, logging in, or recording which pages were visited in the past). They can also be used to remember arbitrary pieces of information. the information user previously entered into form fields such as names, addresses, passwords, and credit card numbers.
Reason Behind using Cookie-Free Domains
Cookies are very useful in some cases, in other cases – such as the delivery of static content, they can hinder performance. When a browser makes a request for a static asset such as an image or CSS file, there is no need for it to also send a cookie to the server. This only creates additional network traffic and since the files are static (they do not change) the server has no use for the added cookie.
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 elimination unneeded network traffic.
How to use Cookie-Free Domains?
If you set your cookies on a top-level domain (e.g. yourwebsite.com) all of your sub-domains (e.g. static.yourwebsite.com) will also include the cookies that are set. Therefore, in this case, it is required that you use a separate domain name to deliver your static content if you want to use cookie-free domains. To reserve a cookieless domain for serving static content, you have to register a new domain name and configure your web server to serve static resources from the new domain, and do not allow any cookies to be set anywhere on this domain. If you set your cookies on a www subdomain such as http://www.yourwebsite.com, you can create another subdomain (e.g. static.yourwebsite.com) to host all of your static files which will no longer result in any cookies being sent.
The following steps outline how to use cookie-free domains in WordPress:
1 Create a subdomain such as static.yourwebsite.com which is where you will deliver all your static files from.
2 Point your new subdomain to the /wp-content directory of your WordPress installation. For cPanel users, you will need to update the document root field from public_html/static to public_html/wp-content like the screenshot below.
3 Edit your wp-config.php file to reflect the following:
define(“WP_CONTENT_URL“, “http://static.yourwebsite.com“);
define(“COOKIE_DOMAIN“, “http://www.yourwebsite.com“);
?>
4 Run the following command in your SQL database, this will ensure all post URLs are directed to the new subdomain:
Now that your cookie domain and static content subdomain are set. you can begin delivering static content without the server setting an unnecessary cookie for static assets.
[…] 28.Serve static content from a cookieless domain: To increase the loading speed of a website, you need to setup your website to serve the static content, such as images and css files, from a cookieless domain. This will speed up your page loads by reducing unnecessary traffic and distributing the traffic across more two addresses instead of one, working around the limit that browsers place on how many simultaneous requests can be made on each address. As described by Yahoo!, when the browser requests a static image and sends cookies with the request, the server ignores the cookies. These cookies are unnecessary network traffic. For more about cookieless domains read our post – How to use Cookie-Free Domains for static content […]
Hi! I tried the steps and at SQL part, I get this error #1054 – Unknown column ‘’www.beclockwise.ro’ in ‘field list’. I tried it on the correct database.
My entry is UPDATE wp_posts SET post_content = REPLACE(post_content,’www.beclockwise.ro/wp-content/’,’static.beclockwise.ro/’)
Any suggestion?
Thank you!
When I input the above code then my website doesn’t work CSS or JS. Could you please let me know how can solve it?
Followed instructions to a tee, but unfortunately this method did not produce the desired results.
Hello Mark, Can you please elaborate what issue you are facing?