Create Cookie Free Domain for WordPress

By Avinash

July 13, 2011Tutorial26 Comments

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.

define("WP_CONTENT_URL", "http://static.yourdomain.com"); define("COOKIE_DOMAIN", "www.yourdomain.com");
define("WP_CONTENT_URL", "http://static.yourdomain.com");
define("COOKIE_DOMAIN", "www.yourdomain.com");

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.

Share This Article

  • Sanjay

    Thanks it helps me.
    But can you Please explain little bit more?

    It works for me but i dont know how it works?

  • http://ultimatepasses.blogspot.com ads

    very helpful for me.

  • Pingback: My Stream » 10 Quick Tips: Optimizing & Speeding Up Your WordPress Site

  • Pedro

    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

  • Praveen Gowda I V

    Hello, but my blog has been already there for a long time
    Noe how can I switch to CDN

  • Pingback: 10 Quick Tips: Optimizing & Speeding Up Your WordPress Site | Graphfucker

  • Pingback: 10 Quick Tips: Optimizing Your WordPress Site | Wptuts+

  • http://freakify.com Ahmad Awais

    Great article !
    Tell me my other plugins like w3cache will be affected or not?

  • Pradeep Kumar Jangid

    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.

  • Pingback: 10 ??????? ?? ????????? ?????? ????? ?? WordPress | Wordpresso

  • Pingback: Wordpress Notes | notes.dvsi.net

  • Ayan

    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….

  • Pingback: Disable Cookies using .htaccess file | Expert PHP Developer

  • http://ccnplessons.com Muhammad

    Should i have anything when i open http://static.mydomain.com?

    i got blank page anyways, i don’t get it!

    • http://www.xpertdeveloper.com Avinash

      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/

  • KD Gates

    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.

    • http://www.xpertdeveloper.com Avinash

      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.

      • http://www.celsaderm.com KD Gates

        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.

  • Mike The spike

    Thank you that’s great

  • Pingback: 10 Quick Tips: Optimizing & Speeding Up Your WordPress Site

  • Pingback: Cookie Free Domain Doesn't work - feed99

  • http://www.tongkronganbandung.com Zefri Kurnia

    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)

  • Javier

    We can download your PHP files located in wp-content, because they are “static”. Is this suppossed to work like this?

  • Chirag Vora

    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.

  • cleansites

    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