Image caching and redirects to deal with default images
===

I'm interested to see how people would solve this, or if it can be done using redirects.

On sites a common problem is having an icon to represent a resource (say a user), and if this resource does not exist, having a default icon.

Now say I want to solve this in the markup then it's quite simple:

    # Default for user without an icon
    <img src="/images/default.png" alt="theozaurus">

    # For user with an icon
    <img src="/images/users/theozaurus.png" alt="theozaurus">

However, there are some scenarios where this can be a pain:

 - Prerendered markup (a user might upload an icon after the markup has been created)
 - Dynamically generated markup in the browser (it may be expensive to discover if the user has an icon or not, and instead it would be nice to have simple/quick logic for generating the correct url).

So the solution seems obvious:

    <img src="/images/users/theozaurus.png" alt="theozaurus">

Then the app can either return the default icon, or the proper one that been uploaded. This is inefficient though as if I have a page with 100 of these icons, and 90% of them are default icons, I'm effectively downloading the same image 90 times, just because I don't want to deal with the prerendered or dynamically generated markup problems.

Would it work (be sane), if I solved this using redirects - and would caching still work.

For example a `GET` to `/images/users/theozaurus.png` could return a `302 /images/default.png`. Then when theozaurus uploads an icon, it would return `200 <unique icon>`

Will browsers get a cache hit on the redirect? Are there any pitfalls that I have missed here?