Quick ASP.NET Performance Tips

        Introduction:


                    Sometimes some quick tweaks can boost your application performance. That is changing a little can lead to greatly improve the performance of your application. In this article, I will show you how to increase the application performance with minimal changes in the code.


        Description:

 

 

Tip:  By making static resources cacheable for long periods of time will greatly improve application performance. You don't need to be panic about file changes because the browser will automatically grab the fresher copy of the file if the file is changed on server. See Making Cache Aware ResolveUrl/Url.Content and Cache busting in ASP.NET.

 

 

Tip:  By leveraging ETag(or Last-Modified) http header will greatly save the precious network bandwidth and client/server resources. A simple ASP.NET response filter will greatly save the browser and server time. You can find a simple ETag filter which are based on html contents hash at here and here. Similarly the same trick with some small changes can be used for Last-Modified http header.

 

 

Tip:  By enabling compression in your application will allows you to greatly reduce the response size which will help the clients(browsers) to quickly grab the response from server. You can enable compression in ASP.NET using URL Compression <urlCompression>.

 

 

Tip:  By bundling and minifying external scripts and style-sheets will help you to reduce the download size and time which will also improves application performance. Here is a great resource about Bundling and Minification. For minifying inline scripts and style-sheets check Bundling and Minifying Inline Css and Js

 

 

Tip:  According to Google Techniques and Best Practices redirecting user will adversely effect the performance of mobile web application. So, if possible then use Server.Transfer instead of Response.Redirect(Redirect in MVC). Response.RedirectPermanent is also better than Response.Redirect but Server.Transfer avoids the extra browser-to-Web-server round trip. 

 

 

Tip:  CSS sprite will also quickly raise your application performance. You can easily enable it using ASP.NET Sprite and Image Optimization

 

 

Tip:  Most of the time, images takes the largest percentage(in size) of a web page. Optimizing images will automatically make your web pages run faster. Lossless compression(sometimes lossy also help) will dramatically reduce the complete page size. Making mobile optimized images will also improve the performance in mobile devices. Also, I always resize my images if they are greater than a particular size limit. I use jpegtran.exe for compressing jpeg images and in all other cases I use imagemagick in my cron job which works in the background process on server. For lossless compression of jpeg I use jpegtran -copy none -outfile "{0}" -optimize "{0}" and for png I use mogrify -strip "{0}". For resizing an image(be for creating a mobile optimized image or for limiting the maximum size) I use convert "{0}" -resize 200x200 "{1}". Note mogrify.exe and convert.exe will be available once you download the imagemagick. Putting/using these commands in your .NET code is very easy.


 

                    Web Performance Best Practices and Best Practices for Speeding Up Your Web Site are great references.

 

        Summary:


                    In this article, I showed you how to quickly increase your application performance using some simple tricks. Hopefully you will enjoy my this article too.



4 Comments

Comments have been disabled for this content.