1

Lets say I have a static website at example.com, it does not set any cookies. I have tracking on stats.example.com and a git server on git.example.com - both of which do set cookies.

Static assets are served from cdn.example.com, this should be a cookie-less domain.

Will hosting my main website at the root domain (example.com) cause any issues with cookies on the subdomains in this scenario?

  • You don't use any third party scripts that set cookies? Like Google Anyalytics? – Stephen Ostermiller Feb 26 at 13:55
  • I self-host Fathom on stats.example.com, and that does set a cookie. I thought the cookie was set for the stats subdomain, but it seems to be set for the website domain. Dammit. – Thomas Jensen Feb 26 at 14:17
  • 1
    In my opinion cookieless subdomains are not usually worth it. A few small cookies for analytics aren't worth worrying about. If you use 4k of cookies then you should consider it. – Stephen Ostermiller Feb 26 at 15:27
  • Hm, yeah. Maybe I got caught up in generic advice... What about the security aspect of it? Fine as long as I control all subdomains? – Thomas Jensen Feb 26 at 19:15
2

Having a cookiless subdomain is largely un-needed unless you have either really large cookies or a very high traffic site. Having a cookiless domain for static content serving is quite common with high traffic sites as it does provide a measurable reduction in bandwidth usage and download speed, but this is only on high traffic sites. Low and medium traffic sites are generally better off doing site optimisation than worrying about cookies to start with.

As for how to implement generally cookies are set for the root domain and accessible to all sub domains by default unless you change where the cookie is attached to. In this case the cookie will still be a part of the request response cycle for a related sub domain. The most common method of having a cookiless domain is to have a completely stand alone domain for your static content which is different to your sites domain such as...

www.example.com and www.examplestatic.com

A good brief overview of the advantage of cookiless static content delivery can be found at StackExchanges own cdn which is https://cdn.sstatic.net/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.