asp.net mvc消耗asp.net Web api端点 [英] asp.net mvc consuming asp.net web api end point

查看:77
本文介绍了asp.net mvc消耗asp.net Web api端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看着这个问题:

SO问题

Darin Dimitrov接受的答案看起来很吸引人(.NET 4.5版本).我只是想知道如何将性能与客户端解决方案(例如使用敲除/角度/jquery)进行明智的比较,从而在Web api端点给定JSON的情况下组装HTML.有人曾经做过一些性能测试吗? 客户端解决方案"与剃刀服务器端"解决方案的优缺点是什么?

The accepted answer by Darin Dimitrov looks appealing (.NET 4.5 version). I am just wondering how this compares performance wise with client side solutions (e.g. using knockout/angular/jquery) to assemble the HTML given some JSON from the web api endpoint. Did someone ever do some perfromance tests on this. What are the pros and cons of the 'client side solution' vs the 'razor server side' solution?

推荐答案

您应该定义性能.

但是,这两个选项之间有很大的区别:

However there is a very big difference between the two options:

  • 如果您在客户端(使用ko/ng/jQuery)进行此操作,则服务器仅执行API控制器操作并返回格式化的数据.
  • 如果在服务器端执行此操作,则除了执行API操作外,服务器还必须执行MVC控制器操作,因此,毫无疑问,服务器会执行更多工作.

唯一的结论是,在第一种情况下,服务器要做的工作较少.而且,通常,网络流量会减少(JSON对象通常比渲染的局部视图轻).

The only conclusion is that the server has less work to do in the first case. And, usually, the network traffic is reduced (a JSON object is usually lighter than a rendered partial view).

如果我们要谈论用户体验,那么一般的客户端技术(jQuery,ko,ng)都可以提供更好的用户体验,因为页面的响应速度更快:显示/隐藏元素很容易,设置焦点,进行微不足道的计算,进行远程验证...如果我们使用现代的库,我们可以进一步提高接口的适应性.例如,breeze.js允许在客户端缓存数据,以避免对服务器进行额外的ajax调用,从而提供了响应速度更快的体验,尤其是在您预期需要哪些数据并事先对其进行缓存的情况下.您甚至可以将数据持久保存在HTML5存储中,以便将其用于其他会话.

If we're speaking about the user experience, in general client side technologies (jQuery, ko, ng) offer a much better user experience becasue the page is much more responsive: it's easy to show/hide elements, set the focus, make trivial calculations, remote validations... And if we use modern libraries, we can go further on improving the interface resposiveness. For example breeze.js allows to cache data in the client side to avoid making extra ajax calls to the server, giving a much more responsive experience, specially if you anticipate what data can be needed and cached it before hand. You could even persist data in HTML5 storage, so that it's available for other sessions.

然后,从用户的角度来看,我认为第二种选择要好得多.而且服务器要做的工作更少,这可以使其在高流量站点中更具针对性.

Then, from the user viewpoint, I think it's much better the second option. And the server has less work to do, which can make it also more resposive in high-traffic sites.

即使如此,我也不知道什么是更好的表现",甚至什么也不是要表现的".

Even so, I don't know what is "more performant" or even what it is "to be performant".

无论是什么,使用客户端技术都是更好的选择.但是掌握相关技术需要一些时间.

Whatever it is, using client side technologies is a much better option. But it takes some time to master the associated technologies.

这篇关于asp.net mvc消耗asp.net Web api端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆