WebPagetest Forums
Serving static content from a cookieless domain - Printable Version

+- WebPagetest Forums (https://www.webpagetest.org/forums)
+-- Forum: Web Performance (/forumdisplay.php?fid=3)
+--- Forum: Optimization Discussions (/forumdisplay.php?fid=5)
+--- Thread: Serving static content from a cookieless domain (/showthread.php?tid=128)

Pages: 1 2

Serving static content from a cookieless domain - Naresh - 12-22-2009 01:53 AM

I have two questions, could be silly though Smile

1. Instead of serving static content from a cookieless domain, can we serve static content from a sub-domain?
2. And how to configure it as a cookieless sub-domain or domain ( if sub domain is really not possible)?

Just an additional information that we are using our domain as http://www.example.com ( not as example.com).

Thanks in anticipation.

RE: Serving static content from a cookieless domain - pmeenan - 12-22-2009 07:28 AM

1 - You could serve the content from a different sub-domain but if you set any cookies to the top domain it would defeat the purpose.

For example...If your website is at http://www.example.com you could serve static content from images.example.com as long as you never set cookies to example.com (and set them to http://www.example.com instead).

2 - There's really no explicit concept of a "cookieless domain" it is just by convention that you NEVER set cookies on that domain from your pages.

RE: Serving static content from a cookieless domain - Naresh - 12-23-2009 03:30 AM

Thanks very much for your valuable input. We are serving our static content from sub domain/s and having cookies set up at the domain level ( http://www.example.com). We do need cookies at domain level and can't get rid of these.

I was going through this blog http://www.pubbs.net/nginx/200909/84064/ where in first paragraph Nick mentioned that it is possible to have cookieless sub domain in such situations, but didn't mention how? and there is no link to ask him a question either. Wondering is there real way to this or it was just a guess Smile

RE: Serving static content from a cookieless domain - wasimasif - 12-28-2009 04:22 PM

to make sub domain cookie less see this discussion http://blog.wasimasif.com/serving-images-from-cookie-less-domain/

If you must share cookies for all sub domains you should use completely separate domain to serve static content. For example your domain is http://www.mydomain.com and all images on the page can be served from http://www.myimagedomain.com. For example face book logo is being served from http://static.ak.fbcdn.net/

RE: Serving static content from a cookieless domain - Naresh - 12-30-2009 02:49 AM

Thanks wasimasif. This was great. I found another link in comments section of your blog, how to create cookieless sub domain. I 'll try that and will keep you guys posted. The link was http://www.kensfi.com/serve-static-content-from-a-cookieless-domain/

RE: Serving static content from a cookieless domain - Naresh - 12-31-2009 04:41 AM

I think I got the answer from Yahoo http://developer.yahoo.com/performance/rules.html link It says :

Use Cookie-free Domains for Components

tag: cookie

When the browser makes a request for a static image and sends cookies together with the request, the server doesn't have any use for those cookies. So they only create network traffic for no good reason. You should make sure static components are requested with cookie-free requests. Create a subdomain and host all your static components there.

If your domain is http://www.example.org, you can host your static components on static.example.org. However, if you've already set cookies on the top-level domain example.org as opposed to http://www.example.org, then all the requests to static.example.org will include those cookies. In this case, you can buy a whole new domain, host your static components there, and keep this domain cookie-free. Yahoo! uses yimg.com, YouTube uses ytimg.com, Amazon uses images-amazon.com and so on.

Another benefit of hosting static components on a cookie-free domain is that some proxies might refuse to cache the components that are requested with cookies. On a related note, if you wonder if you should use example.org or http://www.example.org for your home page, consider the cookie impact. Omitting www leaves you no choice but to write cookies to *.example.org, so for performance reasons it's best to use the www subdomain and write the cookies to that subdomain.

RE: Serving static content from a cookieless domain - vajra - 01-24-2010 01:42 AM

Hi everyone, just discovered this amazing site! Really well thought out & put together.

I ran a test on my site & saw that I need to Enable browser caching of static assets. Searching to find out more I found this thread instead. It seems really interesting.

Do I understand this correctly?... When images are downloaded cookies get downloaded with them too? So if I put my images on a separate domain which does not use cookies I will get a faster response time? That would also apply to style sheets etc?

Sorry if this is a real newbie kind of question.


RE: Serving static content from a cookieless domain - pmeenan - 01-24-2010 03:24 AM

Sort of. When images or style sheets are requested, the request includes any cookies for the domain. It doesn't usually make a HUGE difference but sending the cookies up to the server takes time (more so than downloading since the upload bandwidth is usually quite a bit less than the download bandwidth). Putting the static content on a different domain keeps the requests clear of cookies and makes them a bit faster.

The cookies (and ETags) are the least important of the optimizations though and at best will save a few milliseconds. Making the static assets cachable can have an ENORMOUS difference for a repeat visit (50-90% faster).

RE: Serving static content from a cookieless domain - symkat - 09-23-2010 05:39 AM

Using another domain to serve static content also speeds up the rendering by getting around the concurrent-connections to each domain rule in the browsers.

If you're using a sub-domain of the main domain chances are this will not help with cookies. In the case of your main content being on example.com and then using the sub-domain static.example.com cookies will generally be set for .example.com and thus be sent with requests to static.example.time. This is particularly true with Google AdSense which doesn't allow you to limit the domain the cookie is set for.

I wrote an article about this subject, including speed tests with Chrome and Keynote for the before and after: http://symkat.com/105/cookieless-domains/

I hope this is helpful. Heart

RE: Serving static content from a cookieless domain - noxray - 01-08-2011 07:52 AM


we have the same problem. We write a new Domaincheck and images are really slow http://www.internex.at/de/domain/domain-check.php

Should we use a second domain for images?