Forum Moderators: phranque

Message Too Old, No Replies

Handling images that may not exist

         

ozric

9:49 am on Oct 28, 2007 (gmt 0)

10+ Year Member



Hi

In my .htaccess file, what is most efficient way of handling images which may or may not exist?

Should I just use:

ErrorDocument 404 /thumbs/blank.jpg

or would something like this be better:

RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule .* /thumbs/blank.jpg

Which would put the least strain on my apache server if the image directory has 10,000 + files in it, and 50% of the requests will be for images that don't exist?

Thank you,

Dave

jdMorgan

3:26 pm on Oct 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If this code is to be located in the directory along with the images, I'd use the ErrorDocument method. This is because ErrorDocument is "wired in" to the normal Apache "file exists" checking, whereas using the mod_rewrite method invokes an additional "file exists" check in addition to Apache's default check.

Since calls to the file system are expensive in terms of CPU utilization, and since the server already checks for file exists, I'd avoid adding an additional check, especially since your images directory is likely to be the target of the majority of requests to your server (assuming that each page loads several images).

With that in mind, be sure you're setting proper expires and cache-control headers on that images directory as well -- see mod_expires and mod_headers.

Jim

ozric

6:44 pm on Oct 28, 2007 (gmt 0)

10+ Year Member



Thanks Jim