Every conscientious website owner looks to improve their site visitor’s user experience with their website. Part of this is making sure your web pages are loading quickly. Using EMWD.com as your hosting provider, we provide technologies such as HTTP/2 and Brotli to help with page load times. Sometimes more is needed, especially when using a content management system like WordPress. In this article we are going to particularly focus on improving your page load times with WordPress.
What Are Cookies?
Well in this article, when we mention cookie, we are not referring to the favorite sweet treat of many, but to HTTP cookies.
HTTP cookies are small pieces of data that are sent from a website and stored in your browser. While a user is viewing a website that uses cookies, the cookies collect data pertaining to your website activity such as preferences, shopping cart items, which pages you visited, etc. Cookies are very valuable to many websites as they facilitate a better user experience and are key in performing certain functions such as determining whether a customer is logged in, and with which account.
Each subsequent time the user browses the same website, their browser sends the cookie to the website’s server thus providing it with the information that was set in the last request. There are three main uses for cookies including:
Session management
Personalization
Tracking
Why Use A Cookie-Free Domain?
Although cookies are very useful in many cases, in some cases, such as the delivery of static content, they can hinder site 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 a cookie-free domain, 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.
How to Set Up a Cookie-Free Domain in WordPress
If you set your cookies on a top-level domain (e.g. yourwebsite.com), all of your sub-domains (e.g. store.yourwebsite.com) will also include the cookies that are set. Therefore, in this case, it is required that you use a separate sub-domain name to deliver your static content if you want to use a cookie-free domain. 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. This can easily be done via cPanel and then integrated into your WordPress site. Here’s how to do it:
1. Using cPanel, create a subdomain where you will deliver all your static files from. We recommend using static.yourwebsite.com.
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. Next you will need to edit your wp-config.php file and add the following lines to it:
define(“WP_CONTENT_URL”, “https://static.yourwebsite.com”);
define(“COOKIE_DOMAIN”, “www.yourwebsite.com”);
4. Run the following command in your SQL database, this will 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/’)
We highly recommend installing the WordPress plugin “Better Find and Replace” to do the task of updating your WordPress database.
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. This will improve your page speed scores with GMetrix, Yslow, and Google Insights. It will also provide a better user experience to your website visitors.
You must be logged in to post a comment.