如何提高ASP ?NET MVC应用程序性能?
当前回答
这不是一个惊天动地的优化,但我想我要把它扔在那里-使用CDN的jQuery,等等。
引用ScottGu自己的话:微软Ajax CDN使你能够显著提高ASP的性能。NET Web Forms和ASP。asp.net MVC应用程序使用ASP。NET AJAX或jQuery。这项服务是免费的,不需要任何注册,可以用于商业和非商业目的。
我们甚至使用CDN为我们的web部件在Moss使用jQuery。
其他回答
这不是一个惊天动地的优化,但我想我要把它扔在那里-使用CDN的jQuery,等等。
引用ScottGu自己的话:微软Ajax CDN使你能够显著提高ASP的性能。NET Web Forms和ASP。asp.net MVC应用程序使用ASP。NET AJAX或jQuery。这项服务是免费的,不需要任何注册,可以用于商业和非商业目的。
我们甚至使用CDN为我们的web部件在Moss使用jQuery。
在您嚷嚷着优化客户端时,不要忘记数据库层。我们有一个应用程序在一夜之间从5秒加载到50秒。
在检查中,我们做了一大堆模式更改。一旦我们刷新统计数据,它突然变得像以前一样灵敏。
只是想说说我的意见。优化MVC应用程序中URL路由生成的最有效的方法是…根本不产生它们。
我们大多数人或多或少都知道url是如何在我们的应用程序中生成的,所以只要使用静态Url.Content(“~/Blahblah”)而不是Url.Action()或Url.RouteUrl(),就可以胜过所有其他方法近20倍甚至更多。
PS:我已经运行了几千次迭代的基准测试,如果有兴趣的话可以在我的博客上发布结果。
我做了上面所有的答案,但还是没有解决我的问题。
最后,我解决了我的网站加载缓慢的问题,在发布配置文件PrecompileBeforePublish设置为真。如果你想使用msbuild,你可以使用这个参数:
/p:PrecompileBeforePublish=true
这真的很有帮助。现在我的MVC ASP。NET加载速度快10倍。
我还要补充一点:
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).
推荐文章
- 是什么导致JNI调用变慢?
- 如何从字符串中删除新的行字符?
- 检查属性是否有属性
- 如何快速清除JavaScript对象?
- jQuery Ajax调用和Html.AntiForgeryToken()
- 是否已经添加了事件处理程序?
- Lookup()和Dictionary(Of list()的区别
- 如何从我的c#代码运行EXE文件?
- Node.js vs .Net性能
- 如果使用if-return-return或if-else-return?
- .NET控制台应用程序中的全局异常处理程序
- 枚举上最常见的c#位操作
- PowerShell脚本在机器上返回。net框架的版本?
- 用c#创建一个空文件
- 如何改变列表<T>数据IQueryable<T>数据