How can I get more performance to render my pages using ASP.NET MVC?
How can I get more performance to render my pages using ASP.NET MVC?
The render performance of a View is related to a number of aspects:
View
and in Layout of View
. There is no road map to improve performance that is canonical, but I can try to put together a number of measures to improve the performance of your Views
:
In your ViewEngines
file, use the following commands:
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
In this case, you will only use Razor. If you are using WebForms, use:
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new WebFormViewEngine());
Global.asax.cs
for static pages For example:
public class HomeController : Controller
{
[OutputCache]
public ActionResult Index()
{
return View();
}
}
If the page changes slightly, caching it may be a good solution to avoid using the rendering engine when this is not necessary.
When you publish your system in production, make sure your [OutputCache]
has noted the following:
<compilation targetFramework="4.0" debug="false">
Web.config
that use lots of dependent information This is valid for systems that use some lazy load framework ( Lazy Load ), such as the Entity Framework and nHibernate.
For example, if I load a Person (usually an entity with lots of aggregate data), I should rush the load of information, preventing Lazy Load from causing a performance bottleneck.
var pessoa = context.Pessoas.Include(p => p.Enderecos)
.Include(p => p.Telefones)
.Include(p => p.Compras)
.Include(p => p.Dependentes)
.Single(p => p.PessoaId == pessoaId);