Click here to Skip to main content
15,886,518 members
Articles / Web Development / ASP.NET

ASP.NET MVC Performance Tips

Rate me:
Please Sign up or sign in to vote.
3.50/5 (2 votes)
9 Feb 2015CPOL 14.6K   14   7
ASP.NET MVC Performance Tips

In this post, we will discuss how can we increase the performance of website that uses ASP.NET MVC.

  1. Remove Unused view engines

    C#
    protected void Application_Start() 
    { 
        ViewEngines.Engines.Clear(); 
        ViewEngines.Engines.Add(new RazorViewEngine()); 
    }
  2. Deploying Production Code in Release Mode

    Make sure your production application always runs in release mode in the web.config.

    HTML
    <compilation debug="false"></compilation>
    <configuration> <system.web> 
    <deployment retail="true"></deployment> </system.web> </configuration>
  3. Use OutputCacheAttribute When Appropriate

    MVC will not do any View Look-up Caching if you are running your application in Debug Mode.

    C#
    [OutputCache(VaryByParam = "none", Duration = 3600)]
    public ActionResult Categories() 
    { 
        return View(new Categories()); 
    }
  4. Use HTTP Compression

    Add gzip (HTTP compression) and static cache (images, CSS, …) in your web.config.

    HTML
    <system.webserver><urlcompression dodynamiccompression="true" 
        dostaticcompression="true" dynamiccompressionbeforecache="true"></urlcompression>
    </system.webserver>
  5. Avoid passing null models to views

  6. Remove unused HTTP Modules

  7. ASP.NET MVC ACTION FILTER – CACHING AND COMPRESSION

    Source: ASP.NET MVC ACTION FILTER – CACHING AND COMPRESSION

  8. Put repetitive code inside your PartialViews

  9. Add an Expires or a Cache-Control Header

    XML
    <configuration><system.webServer>
    <staticContent>
    <clientCache cacheControlMode="UseExpires"
    httpExpires="Mon, 06 May 2013 00:00:00 GMT" />
    </staticContent>
    </system.webServer>
    </configuration>
  10. Uncontrolled actions

    C#
    protected override void HandleUnknownAction(string actionName)
    {
           RedirectToAction("Index").ExecuteResult(this.ControllerContext);
    }
  11. Put Stylesheets at the top

  12. Put Scripts at the bottom

  13. Make JavaScript and CSS External

  14. Minify JavaScript and CSS

  15. Remove Duplicate Scripts

  16. No 404s

  17. Avoid Empty Image src

  18. Use a Content Delivery Network

    Use either Microsoft, Google CDN for referencing the JavaScript or CSS libraries

  19. Use GET for AJAX Requests

  20. Optimize Images

The post ASP.NET MVC Performance Tips appeared first on Venkat Baggu Blog.

This article was originally posted at http://venkatbaggu.com/asp-net-mvc-performance-tips

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) eBiz Solutions http://venkatbaggu.com/
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionOne question regarding syntax Pin
Tridip Bhattacharjee13-Feb-15 0:11
professionalTridip Bhattacharjee13-Feb-15 0:11 
AnswerRe: One question regarding syntax Pin
madan53513-Feb-15 2:22
madan53513-Feb-15 2:22 
You can place in a controller, or you can create a common controller and derive from it.

The above can useful when ever request comes from browser the controller searches for an matching action method, when it did not find it throws an error, instead of error page we are simply redirecting the request to the Index method of the controller context.
GeneralRe: One question regarding syntax Pin
Tridip Bhattacharjee16-Feb-15 1:48
professionalTridip Bhattacharjee16-Feb-15 1:48 
GeneralRe: One question regarding syntax Pin
madan53516-Feb-15 2:20
madan53516-Feb-15 2:20 
GeneralRe: One question regarding syntax Pin
Tridip Bhattacharjee16-Feb-15 21:57
professionalTridip Bhattacharjee16-Feb-15 21:57 
GeneralRe: One question regarding syntax Pin
madan53517-Feb-15 2:06
madan53517-Feb-15 2:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.