如何提高ASP ?NET MVC应用程序性能?
当前回答
在您嚷嚷着优化客户端时,不要忘记数据库层。我们有一个应用程序在一夜之间从5秒加载到50秒。
在检查中,我们做了一大堆模式更改。一旦我们刷新统计数据,它突然变得像以前一样灵敏。
其他回答
我还要补充一点:
Use Sprites: Sprites are a great thing to reduce a request. You merge all your images into a single one and use CSS to get to good part of the sprite. Microsoft provides a good library to do it: Sprite and Image Optimization Preview 4. Cache Your server object: If you have some references lists or data which will change rarely, you can cache them into memory instead of querying database every time. Use ADO.NET instead of Entity Framework: EF4 or EF5 are great to reduce development time, but it will be painful to optimize. It's more simple to optimize a stored procedure than Entity Framework. So you should use store procedures as much as possible. Dapper provides a simple way to query and map SQL with very good performance. Cache Page or partial page: MVC provides some easy filter to cache page according to some parameters, so use it. Reduce Database calls: You can create a unique database request that returns multiple objects. Check on Dapper website. Always have a clean architecture: Have a clean n-tiers architecture, even on a small project. It will help you to keep your code clean, and it will be easier to optimize it if needed. You can take a look at this template "Neos-SDI MVC Template" which will create a clean architecture for you with lots of performance improvements by default (check MvcTemplate website).
这不是一个惊天动地的优化,但我想我要把它扔在那里-使用CDN的jQuery,等等。
引用ScottGu自己的话:微软Ajax CDN使你能够显著提高ASP的性能。NET Web Forms和ASP。asp.net MVC应用程序使用ASP。NET AJAX或jQuery。这项服务是免费的,不需要任何注册,可以用于商业和非商业目的。
我们甚至使用CDN为我们的web部件在Moss使用jQuery。
在您嚷嚷着优化客户端时,不要忘记数据库层。我们有一个应用程序在一夜之间从5秒加载到50秒。
在检查中,我们做了一大堆模式更改。一旦我们刷新统计数据,它突然变得像以前一样灵敏。
我做了上面所有的答案,但还是没有解决我的问题。
最后,我解决了我的网站加载缓慢的问题,在发布配置文件PrecompileBeforePublish设置为真。如果你想使用msbuild,你可以使用这个参数:
/p:PrecompileBeforePublish=true
这真的很有帮助。现在我的MVC ASP。NET加载速度快10倍。
只是想说说我的意见。优化MVC应用程序中URL路由生成的最有效的方法是…根本不产生它们。
我们大多数人或多或少都知道url是如何在我们的应用程序中生成的,所以只要使用静态Url.Content(“~/Blahblah”)而不是Url.Action()或Url.RouteUrl(),就可以胜过所有其他方法近20倍甚至更多。
PS:我已经运行了几千次迭代的基准测试,如果有兴趣的话可以在我的博客上发布结果。
推荐文章
- c# .NET中的App.config是什么?如何使用它?
- 如何找到Java堆大小和内存使用(Linux)?
- 在哪里放置AutoMapper.CreateMaps?
- String类中的什么方法只返回前N个字符?
- 如何在HTML5中改变视频的播放速度?
- 我如何提高ASP。NET MVC应用程序性能?
- 无法解析类型为“Microsoft.AspNetCore.Http.IHttpContextAccessor”的服务
- 如何在没有任何错误或警告的情况下找到构建失败的原因
- Visual Studio弹出提示:“操作无法完成”
- 否ConcurrentList<T>在。net 4.0?
- 在c#中解析字符串为日期时间
- 如何在剃刀视图上引用.css文件?
- 由Jon Skeet撰写的《Singleton》澄清
- 自定义数字格式字符串始终显示符号
- 列表推导式和函数式函数比for循环更快吗?