CDN

Setting up cookieless fake CDNs for Drupal

So you want your Drupal site perform as quick as possible and you have set up CDN and patched imagecache and everything is working fine. Then you realize that any asynchronously generated static resource (e.g. image, stylesheet, etc.) will naturally send a session cookie to your visitors.

The very promising Advanced CSS/JS Aggregation and ImageCache both handle requests in a unique way: if the requested resource is not generated yet, it will run through Drupal, create the resource and place it in the path exactly where the request points to. This way, subsequent requests does not need to go through Drupal and PHP again, it can be served as a static resource.

However since the first request runs through Drupal, it will start a session (Drupal 6 by default starts sessions for anonymous users) This is okay if you use a single domain to serve files from. Things get annoying when you start using alternate host names to speed up page loading times, and you realize that these precious alternate host names start sending out session cookies to your visitors, and you are basically doubling (or with 3 cname domains, that is quadrupling) your session rows if a visitor happens to hit a static resource for the first time.

CDNs - even if they are just fake CNAME records pointing to the same webroot - should operate cookieless to keep the http request headers as short as possible for subsequent requests.

One could (eliminate anonymous sessions)[http://2bits.com/articles/reducing-server-load-eliminating-anonymous-sessions-drupal-6x.html] easily from the entire site, but that might not be your cup of cake because anonymous sessions are needed so much say on an Ubercart site to track cart contents.

My solution is to use an alternate session handler which in fact does not handle sessions at all. Configure this session handler to be fired only at your cdn domains and you're set to go.