If you are thinking of speeding up your website, Google might be telling you the answer is to create a cookieless subdomain or domain. Now, are you thinking of serving static content from a subdomain? Or, should I ask what is a cookieless subdomain?
One thing for sure, there is absolutely nothing to do the giving out those yummy cookies for tea time.
Instead, you can consider a cookieless subdomain is a term to describe data transferring from one point to another (in this case, data movement from subdomain to domain) has no cookies attached. Indirectly, this boost the loading speed of your domain.
This is what Google explain with its own words:
Serving static content or resources from a cookieless domain reduces the total size of requests made for a page.
Static content, such as images, JS and CSS files, don’t need to be accompanied by cookies, as there is no user interaction with these resources. You can decrease request latency by serving static content from a domain that doesn’t serve cookies. This technique is especially useful for pages referencing large volumes of rarely cached static content, such as frequently changing image thumbnails, or infrequently accessed image archives. We recommend this technique for any page that serves more than 5 static resources. (For pages that serve fewer resources than this, it’s not worth the cost of setting up an extra domain.)
As you read above, all static contents or data that are transferred with the accompany by cookies. Though cookies are not needed for any transaction and does not serve any advantage, they will be automatically be available for all data transfer. The only way to avoid such is when static contents are obtained from a cookieless site.
Hate the reading? Don’t worry as I got that covered as well! The below are the slides instead.
Create a cookieless subdomain using CNAME
When it comes to creating a cookieless subdomain, using a CNAME could be easiest way of all. What you need to do is to head over to your cPanel and create a subdomain. You may choose any name to be your subdomain for serving static content to your main domain. For me, I am using static.reginaldchan.net as my CDN subdomain.
Selecting the right installation path for the subdomain
In order to create a proper cookieless subdomain, you have to ensure that when you are creating your subdomain, make sure it is pointing to your root directory instead of creating a secondary one. For example, my root directory is /public_html and thus, it should be pointed or directed to /public_html and not the default, /public_html/static.
Editing the DNS Zone
Once you have done pointing the subdomain, head over to your DNS Zone Editor. At times, these might be labelled as Simple or Advanced DNS Zone Editor for several types of cPanel but they are all alike.
You would need to either create or modify the Name to your subdomain name and CNAME as your main domain. Of course, for the Type, you would need to select CNAME. You may start this by hitting the create button and if there is already a record, you just need to modify the settings to the above.
Still not sure? Let me explain to you in other words. When you create the CNAME record you want to enter your static domain/subdomain as the “label”, “name”, or “alias” and your A record domain as the “content” or “value”. (The CNAME term, which stands for “Canonical Name”, actually refers to the domain you are mapping to, not the alias. The common practice of referring to the alias as the “CNAME” is in fact backwards.)
Making sure the subdomain is cookieless
I could not emphasize how important this is but you must not skip this step no matter what. In WordPress, there are two common cookie-setters which are WordPress and Google Analytics. All you need is to do a little changes in the configurations and you would be well on your way to a cookieless subdomain.
For WordPress, head over to your wp-config by login into your cPanel. Open it up and add this line in the file. If you are wondering where exactly you may place this file, you can place it at the bottom most of the script.
This is definitely a no brainer but just to make sure, do remember to change your domain to your own domain name. After that, save the file and you are good to go!
For Google Analytics, all you need to do is to search for the specific code you had earlier placed in on your site and replace the code with the below one. For a quick tip, most Google Analytics code are kept close to the <body>.
Again, change your domain as seen above to your own domain URL and save the file.
Important note: If you are using cloudflare or any type of Content Network Delivery (CDN), please get your hosting and CDN provider to verify on the CNAME. For example, using Cloudflare will give you an error when you are following the above guide in changing the CNAME. Basically, the hosting or CDN provider will give you a new A figure to place in.
You are all done!
Now, treat yourself to a bottle of beer for the hard work and congratulations. You had managed to create a cookieless subdomain from scratch. This is one of the cheapest (and fastest) way to create a cookieless subdomain when it comes to serving static content to improve your website speed.
If you like this article, could you please share this for me using the red Google+ button below?