As we know that performance is an important part for every application on production. If any website is facing issue of performance then the users do not prefer to use that website. There are many ways to improve the performance of a website in ASP.NET MVC. I am going to demonstrate one by one.
Step 1: Release Mode Build
You should always use the debug build on production. You should make sure that application is compiled in Release Mode rather than Debug Mode.

You need to make changes in Web.Config on Production, when going to deploy the ASP.NET MVC application. Make sure compilation debug mode should be false.

Step 2: Use Single View Engine
As you know in ASP.NET MVC, we can use multiple View Engines; it can be Web Forms [Aspx] orRazor [cshtml] or you can also create your own custom engine to process the ASP.NET MVC Views. We can also configure all engines in same application.
You need to care two things before setting up the engine for the MVC application. Firstly, Engines list should be clear before setting up new engine and only one engine should be setting up.
- protected override void OnApplicationStarted()
- {
- ViewEngines.Engines.Clear();
- ViewEngines.Engines.Add(new RazorViewEngine());
- base.OnApplicationStarted();
- AreaRegistration.RegisterAllAreas();
- RegisterGlobalFilters(GlobalFilters.Filters);
- RegisterRoutes(RouteTable.Routes);
- RegisterBundles(BundleTable.Bundles);
- Register(GlobalConfiguration.Configuration);
- RegisterAuth();
- System.Threading.LazyInitializer.EnsureInitialized(ref _initializer, ref _isInitialized, ref _initializerLock);
- }
We used to create client side application with attractive design. So, for this we always prefer to use Jquery/Javascript and CSS. But as we all know these files are downloaded when we are going to access the website. If you are using multiple CSS and Jquery file then it will take more time to load it and it makes your site very slow.
So, you should prefer to use small file which can be loaded faster or single file which load faster rather than multiple file. In MVC there are two concepts behind this Bundling and Minification. This will help your site to make it faster and decrease the load time.
- public static void RegisterBundles(BundleCollection bundles)
- {
- bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
- "~/Content/Jquery/jquery-{version}.js"));
- bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
- "~/Content/Jquery/jquery.unobtrusive*",
- "~/Content/Jquery/jquery.validate*"));
- bundles.Add(new ScriptBundle("~/bundles/JqueryHomePage").Include("~/Content/js/jquery-1.8.3.min.js", "~/Content/Jquery/bootstrap.min.js", "~/Content/Jquery/HomeJquery.js"));
- bundles.Add(new StyleBundle("~/Content/HomeMain").Include("~/Content/Css/style.css").Include("~/Content/Css/font-awesome/css/font-awesome.css", new CssRewriteUrlTransform()));
- }


Step 4: Caching Enabled
Caching has an important role to make the website faster. It increases the performance smoothly. Actually when website uses the Caching features, it provides the facility to use the existing and downloaded file for next process. Using Caching, you can save some kind of files on server memory and use it next time without downloading the new one.
- public class HomeController : Controller
- {
- [OutputCache(Duration = 300, VaryByParam = "none")] //cached for 300 seconds
- public ActionResult Index()
- {
- return View();
- }
- }
- <configuration>
- <system.webserver>
- <staticcontent>
- <clientcache cachecontrolmode = "UserMaxAge" httpexpires="365.00:00:00">
- </clientcache></staticcontent>
- </system.webserver>
- </configuration>
Now a days, mostly site connect with database for rendering the data on View. But as we know if you are going to load heavy data one time, it makes your site slow. So, you should always prefer to bring the small amount of the data one time and render it on the View.
The easiest way to do this is to use Paging with your application and show the minimum data one time, this will help your site to increase performance. You can use Stored Procedure to get the data which is the fastest way and also you can add filtering option in it.
Step 6: Use Sprite Images
Images make your website more beautiful and user friendly. I believe, images help us to understand the concepts easily. But if there are multiple images on single page, it will affect the performance of the site. It is because images take time to download.
So, here you can use Sprite Image which combines the multiple images in one and load in single download. You can install Sprite Image generator with your application.
Or simply using the Web Essentials feature, you can make images as sprite images.

Step 7: Client Side Validation
Validation takes important part because it validates the user data that it is valid or not. But suppose after validating the single data, your site is going to load that means user should wait every time to load your site again and again. So, always prefer to make the validation on Client Side.
It makes your site faster because there is no need to load the site on every input validation. It will show error message if something goes wrong on client side.

Step 8: Use Performance Tools
You can do many things to make your site faster. But sometime, we are confused and unable to figure out when my site is taking much time to load or sometimes there are memory leaks issue. So, in that scenario you can use some tools which can help you to figure out the root causes.
- Dotnet Memory Profiler
- Fiddler
- FireBug
- Google Page Speed Test
- Web Page Test

Thanks for reading the article, hope you enjoyed it.

rizwan alamPosted Oct 16, 2019, 5:48 AM
Nice article
sheshagiri pattarPosted Jun 22, 2018, 1:56 AM
Views running inside mvc application taking very much time what to do? and my dashboard containing very much db calls how to load my application dashboard faster in production?
sunil BhavsarPosted Sep 6, 2017, 2:36 AM
Vary Useful Article.........
Niladri SarkarPosted Jul 28, 2017, 2:38 AM
Damm Good article! Probably one the of best resources I have ever found.... Great work Mukesh :)
Jeevan WijerathnaPosted Oct 24, 2016, 8:16 AM
Useful article
Rajeev PunhaniPosted Feb 26, 2016, 7:01 AM
Nice article.
Pravin MarathePosted Feb 21, 2016, 11:56 AM
Really nice..
AbedElHamid AlWahidyPosted Jan 2, 2016, 5:02 AM
That is great article
Nitin PanditPosted Dec 27, 2015, 12:11 PM
Nice Article dear really Good :)
Padmavathi APosted Dec 23, 2015, 9:02 AM
Very useful article. Thank you for sharing.
Banketeshvar NarayanPosted Dec 22, 2015, 10:54 AM
NIce Share
Suman VermaPosted Dec 22, 2015, 8:20 AM
nice one
Suman VermaPosted Dec 22, 2015, 8:19 AM
Nice one
Aishwarya DPosted Dec 22, 2015, 1:50 AM
Nice one
Sibeesh VenuPosted Dec 22, 2015, 12:09 AM
Nice Share
Jaipal ReddyPosted Dec 21, 2015, 11:34 PM
Nice
Santhakumar MunuswamyPosted Dec 21, 2015, 11:26 PM
Can you upload source code it will be helpful for the beginner
Santhakumar MunuswamyPosted Dec 21, 2015, 11:26 PM
Thanks for sharing.
Ankur MistryPosted Dec 21, 2015, 3:16 PM
We can also implement gZip
Ankur MistryPosted Dec 21, 2015, 3:15 PM
useful information
Manas MohapatraPosted Dec 21, 2015, 11:50 AM
Very informative..
Mahesh ChandPosted Dec 21, 2015, 9:56 AM
This is great, Mukesh. I've found many cases where a website is slow because of database. Developers should go back and profile database including table indexing and run stored procedures to see how much time each of those SPs is taking and improve there. If there are too many joins, create Views. If database is large and very slow, create temp tables and views. Some applications may also need data catching. Web server can also catch pages as well. Cheers!
Ravi PatelPosted Dec 21, 2015, 9:55 AM
very helpful sir thanks
Raja TPosted Dec 21, 2015, 9:41 AM
Nice, Thanks for sharing