I you have an image gallery with dynamically generated thumbnails; you should make sure that the browser is told to cache the thumbnails. If not, each image is generated every time the browser visits. It stresses the CPU unnecessary and the page takes longer to load. If the images where in the browsers cache, the page would load much faster and the images would not be generated on each page request.

If the image gallery consists of multiple pages the visitor can navigate between, the chances are that he or she will visit the same page more than once. For returning visitors, the chances are much higher.

In order to enable browser caching you have to set the Last-Modified header in the .aspx or .ashx that you use to generate the thumbnails.

Here’s an example on how it could be done:

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

That’s all there is to it, and best of all - it’s supported by all major browsers.

A colleague and I had a discussion the other day about the use of curly brackets in C# and when to use them. The use of curly brackets is of course a part of the C# syntax, but you can use them in various different ways. We discussed the two line if-statement, because that’s the only scenario we found us to be in doubt.

Here are two ways of writing the same if-statement with and without the use of curly brackets.

With curly brackets:

if (foo == "enabled")
{
   return true;
}

Without curly brackets:

if (foo == "enabled")
   return true;

We both come from the Visual Basic world where you don’t have curly brackets, and that’s probably why we had this discussion in the first place. The question is which approach is the best? I know it’s a stupid question and a very subjective one, but I’m interested in your opinion on this. What do you think?