ASP.NET MVC - Slow initial load

C#asp.netasp.net MvcWeb Applications

C# Problem Overview


I've recently created an asp.net mvc web application and published it online.

When first loading the website you should find that it takes around 10-15 seconds for it to actually show, however after it's clicked once, it loads as quickly as I expect the second time round. I'm just wondering if anyone may have an idea of why the website is taking so long?

C# Solutions


Solution 1 - C#

Typically an application will always take a little extra time to load as the application domain starts up.

Things helping exacerbate this could be anything from poorly written code (IE: Application_Start) to certain libraries you may be using (ORMs for example). How many modules do you have loaded?

For starters check your web.config for the infamous <compilation debug="true">. That can have significant performance ramifications in a production setup. Set it to "false"!

Recommend googling something along the lines of "improving application startup time" and looking for things that may relate to your particular application.

Update from your first comment:

If you're seeing the application start up again (hangs for a few seconds) after 30 minutes consistently this is likely related to your Application Pool Recycling settings in IIS.

Go into IIS Manager (this assumes v7+):

  1. Application Pools
  2. Right click the pool being used for your application(s)
  3. Select "Recycling", a window will come up labeled "Recycling Conditions"
  4. Inspect those settings since they will determine when to automatically kill your app pool and have it restart.

In terms of general performance you may want to try:

  1. Adding some debugging statements that spit out elapsed time in your Application_Start() method or any other applicable location to try to catch what's taking the longest.
  2. Create a completely clean demo project and deploy it. See if it suffers from the same problem. If it doesn't try introducing more and more of your real code until you detect a slowdown.

If you're really stumped #2 may be your best bet even though it will be probably be the slowest option.

Solution 2 - C#

I also had same problem, with slow first loading asp.net mvc sites, finally I found the best way for load a site, extremly fast in first load.

My solution is for windows server 2008 r2 and IIS 7.5, but in upper windows servers and upper iis versions also work, with some simple diferences.

First of all, you must set startMode of your application pool to always running, this will prevent your application pool from sleeping, after some time. (in my case just this step changes my sites first load from 45-55 seconds to about 8-12 seconds).

in step one, there is no first request for your website, for preloading your website, we need another step, that is by installing Application Initialization module for iis7.5 from here

in step two, you must set preloadEnabled=true for your website, this option is what application initialization added to site settings.

For more information and how you can set these option please refer to this blog post: http://blogs.iis.net/wadeh/application-initialization-part-2

after step two, my web site loads in just 1-3 seconds.

Solution 3 - C#

In addition to what Jay has said.. you should consider the memory usage of your app pool. This is especially true for Shared hosting environments, where your provider will generally recycle an app pool once a memory limit is hit (rather than time-based). This will again cause your site to "restart", causing an initial load perf issue.

Solution 4 - C#

It looks the images which rotate are a bit large. In my browser this part loads the last. All the rest of the page loads pretty fast. You may think of resizing these images. Also, large JavaScript files may cause some slowdown during the initial loading.

Solution 5 - C#

There are few steps to implement :

  1. Client Side Cache
  2. Bundling and Minification
  3. Server Side Cache
  4. Configuring Auto-Start with IIS Manager

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJamie MclaughlanView Question on Stackoverflow
Solution 1 - C#TimeoutView Answer on Stackoverflow
Solution 2 - C#mesutView Answer on Stackoverflow
Solution 3 - C#Simon WhiteheadView Answer on Stackoverflow
Solution 4 - C#feradzView Answer on Stackoverflow
Solution 5 - C#SubhransuView Answer on Stackoverflow