Portal Home > Knowledgebase > Articles Database > Question about Expires headers filename vs CGI params.


Question about Expires headers filename vs CGI params.




Posted by dvogel, 07-27-2007, 01:41 PM
I am setting up Expires headers for my site. The site allows users to upload photos of themselves. The photos are stored as .jpeg. I want these to be cached, but updated when the user uploads a new photo. From what I understand, new browsers use ETags to make sure this happens (since if they upload a new file, the inode and/or mtime will change). However for older browsers, I plan to add ?file-mtime to the end of the file name. This should allow caching but it will change when the user uploads a new image. Will the cause any technical problems with caches that would not be a problem if I changed the filename to be user_id.mtime.jpeg when the user uploads the file? The trade-off is that if I just append ?file-mtime to the end of the filename, I don't have to track these images in a database or use file globs (cpu-expensive for large directories) to find the filename to output.

Posted by dvogel, 07-27-2007, 02:29 PM
Nevermind. As soon as I posted this (of course), I learned that browsers, per the RFC, are supposed to NEVER cache any URLs with query parameters. FF and IE ignore this while Safari and Opera abide by the letter of the RFC.

Posted by mwatkins, 07-27-2007, 03:05 PM
Thus you need to take steps to get rid of the query parameters. You can do this with mod_rewrite, if you are using Apache, and a similar facility exists for users of lighttpd. Edit: Turning something like ?user=foo into /users/foo was discussed not too long ago here: http://www.webhostingtalk.com/showthread.php?t=608696 Once that's done you can then look at what it will take to implement ETags for your application and server environment. Last edited by mwatkins; 07-27-2007 at 03:11 PM.

Posted by mwatkins, 07-27-2007, 03:20 PM
Here's the headers for a component of WHT's own pages: http://www.webhostingtalk.com/images/resources.png There is a short overview of performance and ETags at the Yahoo developers site: http://developer.yahoo.com/performance/rules.html#etags You could also consider using Last-Modified. Either way, you likely have some work to do in your application code to ensure that Last-Modified or ETag headers are sent to the client (browser).



Was this answer helpful?

Add to Favourites Add to Favourites    Print this Article Print this Article

Also Read
WYSIWYG Web Builder 7 (Views: 676)
Sphere Webhosting (Views: 747)