views:

2092

answers:

5

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?

+3  A: 

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.

David Dorward
+1  A: 

The redirects would cause far more network traffic, and far more latency, than simply leaving things as they are.

RichieHindle
+1  A: 

It would redirect the request but the client would still be sending its cookies to the server, so really you accomplished nothing. You would have to directly access the files from a domain that isn't storing cookies for it to work.

Ryan Kearney
+2  A: 

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.

What you could try to do is create a plugin in Joomla that dinamically creates these references.

For example, you have a plugin that when you enter {dinamic_path path} in an article, it appends 'static.example.com/images' to the path provided. So, everytime you need to change the server path, you just change in the plugin. For the links that are already in the database, you can try to use phpMyAdmin to change them in this structure.

It still loses the WYSIWYG hability in TinyMCE, but is an alternative.

GmonC
Thanks for the idea GmonC, but may be beyond my skills. Will the large plugin library both Joomla and Wordpress have, I was mildly hoping I'd find something already along these lines.
Jason Pearce
You can search the extensions directory in Joomla's official website. There's a plugin called "DirectPHP", you could write a 5 lines php script and call it from an article. But I agree that sometimes we just want an already working solution: since it's a cms, it should has some feature already implemented. Well, good luck with the other provided solutions!
GmonC
ATG Dynamo is a commercial (and very expensive!) webapp framework which does this. You work with images in its CMS, and when you deploy content, it can push the images to a dedicated webserver, then generate the right URLs on the pages. It's a nice idea, and surely not all that hard to implement, so i'm surprised it's not more widely done.
Tom Anderson
A: 

What you really want to do is use staticexample.com/images instead of static.example.com/images so that you don't pick up any cookies on the example.com domain that you may have set. If all you do is server images from that domain with a simple apache server or something then you can configure that server not to return even a session cookie.

The redirects are a very bad idea. Cookies cause some performance hits but round trips to the server such as a redirect would cause are a much more serious performance issue.