Web application performance is one of the key factors in online business success.
Here I will share 10 simple tips to increase Asp.net Application Performance drastically.
Now we have few different framework of Asp.net, most of earlier application were written in AspX with code behind, later we started with Asp.net MVC, then now we have Asp.net Core, so when we talk about improving performance, every framework has some different way of processing request, so keeping that in mind in this article I will cover AspX code behind and Asp.Net MVC, about asp.net core I will publish separately.
In earlier asp.net framework Viewstate was one of the main reason to slowdown page load and every time the page post occur, but that was the mechanism to hold data between page post back, so if your some page does not have any form or posting data is not necessary, please turn off Viewstate for that page, just by setting
EnableViewState = "false" in your page directive, that will not affect any other page of that application, but improve the page loading time significantly.
In page html, don’t use any table tag, use all div, span etc, try to use bootstrap css, you get many ready-to-use css classes, which are responsive by default , this will help page rendering faster.
Find out all common data which are being loaded from database when every time page gets loaded, common data means those maser data which remain same, or not going to change very frequently, data like country list, product master etc. you can store them in server side cache object, so instead of pulling them from database, you can fetch them from cache, that will help reducing some time by avoiding unnecessary trip to database server.
You must make sure all images are well optimised for webpage, make images as lighter as possible, so that can be loaded faster, probably you need to take help from some Photoshop expert, there are some tool to make good quality and lighter image for web.
If you use HTTP compression rightly, page size can be reduced to at least 50 percent, it removed all additional spaces in your rendered html, though there is not ready-to-use tool to compress content , but you can write a filter using ActionFiltterAttribute , here is an example of how to write http compression filter in ASP.NET
You can use Page Output Caching, that will help page loading faster, can improve performance drastically, you can set same page caching by parameter also, means depending on parameter different version of same page will be cached in browser, so when user visit the same page, the page will be loaded from cached. Here is an example of how you can implement output caching in asp.net.
if your whole page is displaying dynamic content, but some part of your page has static content, you can use partial caching (known as fragment caching), which means only some portion of page will be cached, not the entire page.
Asynchronous Methods will not block UI of the Page, also will not wait till one task is completely done, and it will keep loading content asynchronously, thus content loading become much faster, and give end user a good experience of browsing your page.
How you fetching data from database that may make huge difference, sometimes even after doing all implementation correctly, application still perform very slow just because of poor data access implementation, though most of Asp.net application uses ORM, LINQ , but here are few simple things may make huge difference.
Avoid using application variable if not necessary, even if using then never store any large data or master data in application variable.
Use session variable only to keep user specific data for that particular duration, and nullify the session object as soon as user leave the site, using too many session variable for multiple users may slow down application performance, so avoid as much possible.
bundles.Add(new StyleBundle("~/Content/css") .Include("~/Content/etg_style.css", "~/Content/wtr.css", "~/Content/bootstrap.min.css", "~/Content/bootstrap.css"));