Free Web Development Online Tutorials, Learn to Code
Learn Asp.net MVC C#, Asp.net MVC Tutorial for Beginners, Model View Controller

How to improve performance in Asp.Net Application

Web application performance is one of the key factors in online business success.

Improve Asp.net Application Performance

ASP.NET application performance improvement

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.

Improve Asp.net Application Performance

  1. Turn off Viewstate

    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.

  2. Use external file reference and some HTML changes

    Try, not to write any in-line CSS or any style block on page, put them all in one css file and add the reference, same for JavaScript code, avoid writing any JavaScript code on page, put all JavaScript in separate file and use the reference , this will help reducing the page size to some extent.

    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.

  3. User server side caching

    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.

  4. Optimise Image Size

    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.

  5. Compress webpage content

    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

  6. Use Page Caching

    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.

  7. Use Asynchronous Methods

    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.

  8. Optimize Data Access Mechanism

    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.

    • Don't write too many joins in DA layer if fetching data from database, rather write view in database (SQL) with all those necessary joins, and then use that object reference in your data access layers.
    • Use server side caching as specified in earlier point.
    • Don't load unnecessary data, fetch and load only data you need to display, in case of paging, use database paging technique, instead of fetching the whole data and creating multiple pages.
    • Make sure all data access objects are nullified and disposed after use, don’t expect everything to be taken care by garbage collector, implement IDisposable interface wherever possible.
  9. Minimize usage of Application and Session variables

    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.

  10. Minify your CSS and JavaScript files

    You can minify all your JavaScript and css files using bundling techniques, in BundleConfig file you can add those files in different bundle like example below.

    bundles.Add(new StyleBundle("~/Content/css")
        .Include("~/Content/etg_style.css",
        "~/Content/wtr.css",
        "~/Content/bootstrap.min.css", 
        "~/Content/bootstrap.css"));       
    
Comment
Name
Email
Website
Subscribe