Does the browser cache dynamic images?
I am currently developing a web application which will be used by multiple clients, and I wish to display the clients logo on each page. The application is being developed using ASP.NET MVC3开发者_运维知识库 and C#.
Normal convention suggests storing images in a database, but given that this image will be displayed on every page, I am concerned about the performance hit of doing this. If I store the image on the file system, the browser will cache the image and wont request it each time.
If I store the image in the database, will the browser also cache this, or will it call the function to request the image each time?
In such a case would I be better off storing the images on the hard disk of the server?
The (modern) browser doesn't know what the server did to store the image. If the URL is the same, the browser will just pull up the cached version unless it was explicitly told not to.
In some circumstances you may need to disable caching: http://www.example.com/random-image
would probably serve up a different image each time it was accessed, and the browser would cache the first image served up.
Set the Response.Cache headers appropriately in your dynamic image controller, and it won't matter that it comes from a dynamic source.
Check this post for an idea for setting caching using an MVC ActionFilter: http://weblogs.asp.net/rashid/archive/2008/03/28/asp-net-mvc-action-filter-caching-and-compression.aspx. It also illustrates the headers you'll need to tweak.
Images are cached by their URLs. If URL has not changed since last load of the page, the image will be taken from cache.
精彩评论