Its better to serve the static contents from separate cookie free domain. Which speed up your website. This is because browser will consider both as a separate domain.
The simplest way to create a cookie free domain in create a sub domain. By default what ever cookies created on main domain will be shared on sub domain also.
But in wordpress we can define that only for which domain it should store the cookies. So it will not get shared on subdomain.
Here are the steps for that:
First create a subdoamin. like cdn.xyz.com, images.xyz.com, i generally use static.xyz.com
Now point this domain to the wp-content directory of the wordpress.
Aftre doing this you need to edit the wp-config.php file which is located at the root of the wordpress.
You need to add below code in your wp-config.php file.
Note: Please make sure that you have used “bloginfo(‘template_directory’)” to load your static content in theme files.
Please check here for more details about cookie free sub domain.
Avinash Zala currently working at a leading web development company as a Sr. PHP Web Developer. He is the founder of the Xpert Developer. He has completed B.E. in Information Technology. Born and brought up in Ahmedabad. He loves to code and coding is all about passion for him. Follow him on twitter at Avinash Zala & Xpert Developer.
View all posts by: Avinash