serving static files via a cookiless subdomain?

Nick Pearson nick.pearson at
Thu Sep 10 04:25:13 MSD 2009

This depends somewhat on how your site stores cookies.  If your
website lives at, it can store cookies at either
"" or just "".  The reason this matters is
that all "" cookies will be sent in requests for
*, but "" cookies will only be sent to
requests at (e.g., not to  As
such, you can use a subdomain (rather than a separate domain) if your
cookies are stored with a "www" prefix.

You can find out some pretty detailed information on this here:

There's a lot of other good information at that site that points out
how to optimize websites for speed.

I doubt if the .mp3 downloads will benefit much from not sending
cookies in the header, mostly because they aren't (usually) downloaded
in quick succession the way images are.  Also note that most browsers
limit to four connections per host while downloading assets, so if you
have a lot, consider spreading them out over multiple subdomains, such
as,, etc.

As far as doing this in nginx, there are many ways.  The simplest
would be to just add more hosts to your server_name declaration.  If
you want to limit the asset hosts to just serving assets, then just
add a new server block:

server {
  server_name ... ;
  root ... ;
  location / {

On Wed, Sep 9, 2009 at 7:01 PM, Ilan Berkner<iberkner at> wrote:
> Hi All,
> We serve MANY .mp3 file and images.  These files hardly ever change so I'm
> thinking about serving them off of a "cookieless" domain per suggestion of
> the yslow component.
> 1. Does it make sense in general to do this?
> 2. How would you do it in Nginx?
> Currently we just have one webserver, we are thinking about adding another.

More information about the nginx mailing list