Reputation: 138
A subdomain is not setting to Cookieless Domain
I have a website to which am trying to serve all the images/css/js
through a cookieless subdomain setup.
So for this abc.com website, I made a subdomain - "static"
and set it to redirect properly to the page assets. But after checking on various tools, such as Gtmetrix or Pingdom, they still showing it's not cookie-free domain
.
I am stuck on what to do next that where I am wrong. Or I will need something to make the subdomain cookieless?
Upvotes: 1
Views: 335
Reputation: 5670
I know it is a four month old question, but have been working on this and what I have learned might help you or another down the road.
Setting up static.abc.com
can work if your main site is www.abc.com
and NOT simply abc.com
. The www
makes all the difference.
If your main site has www
then setting your cookie's Domain
to www.abc.com
will share your cookies with all subdomains of www.abc.com
. This will NOT include static.abc.com
- static
will not be considered a subdomain of www
. So calls to files using static.abc.com
will be cookieless. You will (probably) want to set your cookie's Path
for www.abc.com
to "/" to allow sharing of cookies for all directories under www.abc.com
.
However if your main site doesn't have the www
in the domain (a non-www or naked domain), static.abc.com
is now a subdomain of it and they will share cookies. If this is the case, the only solution is to purchase another domain.
I have a www
domain and I was having the same problem as you - the cookies were being passed with every file on static.mysite.com
. My issue was that I had the Domain parameter of setcookie
without the www
and so the cookies were sharing with all subdomains of mysite.com (which included www
and static
). Once I added the www
, the cookies stopped being sent with static
(verified with GTMetrix).
Hope this makes sense.
Upvotes: 1