.htaccess, YSlow, and "Use cookie-free domains"

Jason Pearce picture Jason Pearce · Sep 16, 2009 · Viewed 71.4k times · Source

One of YSlow's measurables is to use cookie-free domains to serve static files.

"When the browser requests a static image and sends cookies with the request, the server ignores the cookies. These cookies are unnecessary network traffic. To workaround this problem, make sure that static components are requested with cookie-free requests by creating a subdomain and hosting them there." -- Yahoo YSlow

I interpret this to mean that I could experience performance gains if I move www.example.com/images to static.example.com/images.

Although this is easy to do, I would lose the handy ability within my content management system (Joomla/WordPress) to easily reference and link to these images.

Is it possible to use .htaccess to redirect all requests for a particular folder on www.example.com to a folder on static.example.com instead? Would this method also fool the CMS into thinking the images were located in the default locations on its own domain?

Answer

Quentin picture Quentin · Sep 16, 2009

Is it possible to use .htaccess to redirect all requests for a particular folder on www.example.com to a folder on static.example.com instead?

Possible, but counter productive — the client would have to make an HTTP request, get the redirect response, then make another HTTP request.

This costs a lot more than the single line of cookie data saved!

Would this method also fool the CMS into thinking the images were located in the default locations on its own domain?

No.