In this post, we will discuss how can we increase the performance of website that uses ASP.NET MVC.
-
Remove Unused view engines
protected void Application_Start()
{
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
}
-
Deploying Production Code in Release Mode
Make sure your production application always runs in release mode in the web.config.
<compilation debug=”false”></compilation>
<configuration> <system.web>
<deployment retail=”true”></deployment> </system.web> </configuration>
-
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());
}
-
Use HTTP Compression
Add gzip (HTTP compression) and static cache (images, CSS, …) in your web.config.
<system.webserver><urlcompression dodynamiccompression=”true”
dostaticcompression=”true” dynamiccompressionbeforecache=”true”></urlcompression>
</system.webserver>
-
Avoid passing null models to views
-
Remove unused HTTP Modules
-
ASP.NET MVC ACTION FILTER – CACHING AND COMPRESSION
Source: ASP.NET MVC ACTION FILTER – CACHING AND COMPRESSION
-
Put repetitive code inside your PartialViews
-
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>
-
Uncontrolled actions
protected override void HandleUnknownAction(string actionName)
{
RedirectToAction("Index").ExecuteResult(this.ControllerContext);
}
-
Put Stylesheets at the top
-
Put Scripts at the bottom
-
Make JavaScript and CSS External
-
Minify JavaScript and CSS
-
Remove Duplicate Scripts
-
No 404s
-
Avoid Empty Image src
-
Use a Content Delivery Network
Use either Microsoft, Google CDN for referencing the JavaScript or CSS libraries
-
Use GET for AJAX Requests
-
Optimize Images
The post ASP.NET MVC Performance Tips appeared first on Venkat Baggu Blog.