Tutorial

Create Cookie Free Domain for WordPress

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.

Shares:
  • Sanjay
    Sanjay
    July 14, 2011 at 11:06 am

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

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

    Reply
  • ads
    ads
    September 8, 2011 at 2:39 pm

    very helpful for me.

    Reply
  • […] 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 […]

    Reply
  • Pedro
    Pedro
    December 6, 2011 at 6:15 pm

    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

    Reply
  • Praveen Gowda I V
    Praveen Gowda I V
    December 6, 2011 at 7:45 pm

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

    Reply
  • […] For more information on how to setup the Cookie Free Domain for WordPress, look here. […]

    Reply
  • […] For more information on how to setup the Cookie Free Domain for WordPress, look here. […]

    Reply
  • Ahmad Awais ⚡
    December 10, 2011 at 2:54 am

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

    Reply
  • Pradeep Kumar Jangid
    Pradeep Kumar Jangid
    December 20, 2011 at 5:55 pm

    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.

    Reply
  • […] ????? ?????? ?????? ? ???, ??? ?????????? ????? ??? cookie ??? WordPress, ????????? ?????. […]

    Reply
  • Wordpress Notes | notes.dvsi.net
    March 15, 2012 at 3:12 am

    […] http://localhost/xpertdev/2011/07/wordpress-cookie-free-domain/ Bookmark the permalink. « MOH […]

    Reply
  • Ayan
    Ayan
    March 24, 2012 at 9:34 am

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

    Reply
  • […] you want to create a cookie free subdomain for wordpress then you will like this article for […]

    Reply
  • Muhammad
    September 4, 2012 at 9:22 am

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

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

    Reply
  • KD Gates
    KD Gates
    October 7, 2012 at 10:30 am

    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.

    Reply
    • Avinash
      October 8, 2012 at 8:17 am

      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.

      Reply
      • KD Gates
        October 8, 2012 at 9:23 pm

        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.

        Reply
  • Mike The spike
    Mike The spike
    October 7, 2012 at 11:45 pm

    Thank you that’s great

    Reply
  • […] For more information on how to setup the Cookie Free Domain for WordPress, look here. […]

    Reply
  • Cookie Free Domain Doesn't work - feed99
    December 17, 2012 at 1:30 am

    […] I was following this tutorial: http://localhost/xpertdev/2011/07/wordpress-cookie-free-domain/ […]

    Reply
  • Zefri Kurnia
    January 1, 2013 at 1:23 pm

    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)

    Reply
  • Javier
    Javier
    March 1, 2013 at 3:17 am

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

    Reply
  • Chirag Vora
    Chirag Vora
    May 13, 2013 at 1:54 pm

    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.

    Reply
  • cleansites
    cleansites
    August 15, 2013 at 6:09 am

    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

    Reply
  • adsheyn
    adsheyn
    December 20, 2019 at 2:55 pm

    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) !!!

    Reply
  • deprito
    deprito
    February 19, 2015 at 9:04 am

    where i must place “bloginfo(‘template_directory’)?

    Reply
  • Hello Im interested in fixing this issue on my html5 website. Since my site is a non wordpress site will it work for me.

    Reply
    • Avinash
      July 8, 2015 at 12:23 am

      Yes, this tip has nothing to do with WordPress, it will work with your HTML site as well.

      Reply
  • Kevin Allen
    Kevin Allen
    November 22, 2015 at 5:14 am

    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?

    Reply
  • Nice solution indeed. applied it to al3abmizo.com and it works :) thank you

    Reply
  • Anderson
    Anderson
    June 15, 2016 at 1:19 am

    Hey man! This stuff still working?
    If yes, where do I put the “bloginfo(‘template_directory’)”???

    Reply
  • soniya
    August 27, 2016 at 12:29 am

    This is great stuff it will be working for me also.

    Reply
  • Floria Alex
    Floria Alex
    October 19, 2016 at 2:24 pm

    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.

    Reply
  • Features Unlocker
    December 20, 2019 at 2:57 pm

    Nice explaination

    Reply
  • Devender Poonia
    Devender Poonia
    June 24, 2018 at 11:08 am

    it no working for our website http://www.ujjawalpackers.in please help.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *