Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 986
Jason Pearce Avatar asked Sep 16 '09 13:09

Jason Pearce


4 Answers

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.

like image 69
Quentin Avatar answered Nov 06 '22 23:11

Quentin


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.

like image 38
GmonC Avatar answered Nov 07 '22 00:11

GmonC


In theory you could create a virtual domain that points directly to the images folder, such as images.example.com. Then in your CMS (hopefully at the theme layer) you could replace any paths that point to the images folder with an absolute path to the subdomain.

like image 21
Martin Anderson-Clutz Avatar answered Nov 06 '22 23:11

Martin Anderson-Clutz


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

like image 43
RichieHindle Avatar answered Nov 07 '22 01:11

RichieHindle