Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

ASP.NET MVC Performance Tips

0.00/5 (No votes)
9 Feb 2015 1  
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

    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.

    <compilation debug=&rdquo;false&rdquo;></compilation>
    <configuration> <system.web> 
    <deployment retail=&rdquo;true&rdquo;></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.

    [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.

    <system.webserver><urlcompression dodynamiccompression=&rdquo;true&rdquo; 
        dostaticcompression=&rdquo;true&rdquo; dynamiccompressionbeforecache=&rdquo;true&rdquo;></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

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

    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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here