How to cache dynamically generated images for quick page response in ASP.NET ?

Dec 12, 2009 Posted by Lara Kannan
If you have an image gallery with dynamically generated thumbnails, you should make sure to tell the browser to cache the thumbnails.

If you don't, the page will download each image every time the browser visits, which stresses the CPU unnecessarily and causes the page to take longer to load. In contrast, when images are in the browser's cache, the page loads far faster.

If your image gallery contains multiple pages, the chances are good that users will visit the same page more than once. For returning visitors, the chances are even higher.

To enable browser caching, set the Last-Modified header in the .aspx or .ashx that you use to generate the thumbnails, using a date value so that the page always appears unmodified to the browser. Here's an example that sets the last modified date to one year ago:

Response.Cache.SetLastModified( DateTime.Now.AddYears(-1));

I hope this will help you. A 'Thank You' would be nice!

Share
Labels: , ,

Post a Comment