views:

108

answers:

1

With the new "File" ActionResult, I was thinking about creating a controller to display certain images in my ASP.NET MVC app.

Something like:

<img src="/Photo/Show/hello" alt="Hello" title="Hello" />

versus:

<img src="/Photo/Folder/Hello.jpg" alt="Hello" title="Hello" />

I'm curious as to what the performance impact would be. Assuming I did nothing but return the image file from the controller, is there a noticeable performance difference in calling the image from a controller action versus just coding the path into the src attribute?

A: 

Small but measurable performance impact to be sure. However, performance is totally irrelevant until it becomes highly relevant. So unless your server is buckling or your users have to wait for their pages to load, and you need to start mitigating, don't worry about the performance.

DO worry about the following: you will need to re-implement a caching strategy on the server, since IIS manages that for static files requested directly. You will also need to make sure you manage your client-side caching with the correct headers included in the response. Ultimately, just ask yourself if re-inventing a method of serving static files from a server is something that serves your application's needs.

Rex M
That's a good point. What I was thinking was to do more than simply serve static images through the controller. Perhaps implement some security, or some track some statistics. I didn't put that in the original question because those obviously add overhead to serving an image.
Chad