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.
[gads]
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 [code]wp-config.php[/code] file which is located at the root of the wordpress.
You need to add below code in your wp-config.php file.
[cc lang=”php”]
define(“WP_CONTENT_URL”, “http://static.yourdomain.com”);
define(“COOKIE_DOMAIN”, “www.yourdomain.com”);
[/cc]
Note: Please make sure that you have used “bloginfo(‘template_directory’)” to load your static content in theme files.
[gads]
Please check here for more details about cookie free sub domain.
Thanks it helps me.
But can you Please explain little bit more?
It works for me but i dont know how it works?
@ Sanjay: Please have a look at this article, which explain more about the CDN.
http://localhost/xpertdev/2010/08/use-of-content-delivery-network-best-practice-to-speed-up-your-website/
very helpful for me.
[…] content in theme files.For more information on how to setup the Cookie Free Domain for WordPress, look here.Optimization Tip 2: Set an Expire Header for the Static ContentSetting the expire header to far […]
Hello,
have this any implication with affiliate links??
If someone click an affiliate url like http://www.affiliate.com/product from http://www.mydomaing.com, will the cookies still remain in their computers???
Thanks
Hello, but my blog has been already there for a long time
Noe how can I switch to CDN
[…] For more information on how to setup the Cookie Free Domain for WordPress, look here. […]
[…] For more information on how to setup the Cookie Free Domain for WordPress, look here. […]
Great article !
Tell me my other plugins like w3cache will be affected or not?
Dear Xpert,
I use this code in my htaccess file for make cookies free subdomain. but i think it is not working bcz in yslow cookie free domain status showing same before used this code.
I want to make a cookie free subdomain for my site. help me if possible.
[…] ????? ?????? ?????? ? ???, ??? ?????????? ????? ??? cookie ??? WordPress, ????????? ?????. […]
[…] http://localhost/xpertdev/2011/07/wordpress-cookie-free-domain/ Bookmark the permalink. « MOH […]
Hello,
I have a question –
Why your own STATIC sub-domain (http://static.xpertdeveloper.com) not showing as ‘cookie-free-domain’ ?
Same problem with mine also….
[…] you want to create a cookie free subdomain for wordpress then you will like this article for […]
Should i have anything when i open http://static.mydomain.com?
i got blank page anyways, i don’t get it!
no it’s not required to have something on that sub domain as far as it has you assets. Look at mine http://static.xpertdeveloper.com/
Hello, I have searched and searched the website for an answer on how to configure a cookie free domain for Word Press and unfortunately, I keep getting the same thing, a repeat of what Yahoo says to do. In your article, you explain how to set up a cookie free domain but you do not explain how to exactly point the static domain to the wp-content directory. Also, how would I make sure that I have used “bloginfo”? One last thing, where should the “static” folder be located? I think that for developers it is easy to put a few steps and leave it but for those of us who are not developers, we need a bit more help (exact steps). Thanks.
Here are your answers:
1) Process of creating a Domain or Sub domain is totally varies from host to host. May be I will need separate article which shows this process with major hosting provider.
2) Reg bloginfo: you just need to make sure your theme uses that function to load the static content like CSS, JS and Images.
3) Reg static folder point: Its not required to have static folder if you are creating static.xyz.com (varies host to host some may require), but for wordpress what you need to do is point your subdomain to wp-content directory.
Hope this helps.
Thank you for your help. Nothing that I am doing is working for me. I will continue to research to see what I am doing wrong. I have changed everything and WordPress is not picking up the “static” files.
Thank you that’s great
[…] For more information on how to setup the Cookie Free Domain for WordPress, look here. […]
[…] I was following this tutorial: http://localhost/xpertdev/2011/07/wordpress-cookie-free-domain/ […]
Hello, your way is good to speed up the wordpress website..
but you’re not realize when you upload the files, your files will go to your static URL..
for example when you upload image.jpg, so the file will go to static.example.com without the permission..
I was move the files inside wp-content to my static URL, but when I upload the file, I get the file blank (not uploaded)
We can download your PHP files located in wp-content, because they are “static”. Is this suppossed to work like this?
I think clubbing up all possible CSS, JS files and using a CDN will be more useful for speed optimisation than bothering about a cookie free domain.
This is working great. I get a great results when I add the static.mydomain.com. The only problem is I think the css is somewhere else and the page loads without the css. Any idea how I can fix this or what could be causing it?
Thanks
Can somebody please explain me what am I doing wrong?
I’ve Added:
define(“WP_CONTENT_URL”, “http://static.mydomain.com”);
define(“COOKIE_DOMAIN”, “www.mydomain.com”);
to my wp-config.php
Created subdomain for static files: static.mydomain.com
and pointed it to /wp-contetnt folder where all the static files are.
I’ve also changed all the paths to static files from: http://www.mydomain.com/wp-content/...
to: static.mydomain.com/wp-content/
and yes, I’ve used “bloginfo(‘template_directory’)”….
…and ySlow is still showing me: Use cookie-free domains F(0) !!!
where i must place “bloginfo(‘template_directory’)?
Hello Im interested in fixing this issue on my html5 website. Since my site is a non wordpress site will it work for me.
Yes, this tip has nothing to do with WordPress, it will work with your HTML site as well.
hi avinash, I didn’t get it to work. what am i doing wrong? do i still need to do something on htaccess for it to work?
Nice solution indeed. applied it to al3abmizo.com and it works :) thank you
Hey man! This stuff still working?
If yes, where do I put the “bloginfo(‘template_directory’)”???
This is great stuff it will be working for me also.
Hi, can you please highlight the using of “bloginfo(‘template_directory’)”. I have no idea about it. Rest of work was easy to configure but i do not know how to check it or configure it.
Nice explaination
it no working for our website http://www.ujjawalpackers.in please help.