什么是优化的一个asp.net MVC的网站我的JSON的最好方式 [英] what is the best way to optimize my json on an asp.net-mvc site

查看:127
本文介绍了什么是优化的一个asp.net MVC的网站我的JSON的最好方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用的jqGrid上一个asp.net mvc的网站,我们有一个pretty速度较慢的网络(内部应用程序),它似乎是采取网格很长的时间来加载(这个问题是两个网络,以及为解析,渲染)

i am currently using jqgrid on an asp.net mvc site and we have a pretty slow network (internal application) and it seems to be taking the grid a long time to load (the issue is both network as well as parsing, rendering)

我试图确定如何尽量减少我送过来给客户端,使其尽可能地快。

I am trying to determine how to minimized what i send over to the client to make it as fast as possible.

下面是我的控制器操作将数据加载到网格的简化图:

Here is a simplified view of my controller action to load data into the grid:

     [AcceptVerbs(HttpVerbs.Get)]
     public ActionResult GridData1(GridData args)
     {
        var paginatedData = applications.GridPaginate(args.page ?? 1, args.rows ?? 10,
        i => new
           {
       i.Id,
       Name = "<div class='showDescription' id= '" + i.id+ "'>" + i.Name + "</div>",
       MyValue = GetImageUrl(_map, i.value, "star"),
       ExternalId = string.Format("<a href=\"{0}\" target=\"_blank\">{1}</a>",
       Url.Action("Link", "Order", new { id = i.id }), i.Id),
              i.Target,
              i.Owner,
              EndDate = i.EndDate,
              Updated = "<div class='showView' aitId= '" + i.AitId + "'>" + GetImage(i.EndDateColumn, "star") + "</div>",
                                                      })

        return Json(paginatedData);
     }

所以我建立一个JSON(我有大约200条记录以上),并发送回GUI来放在jqGrid的。

So i am building up a json data (i have about 200 records of the above) and sending it back to the GUI to put in the jqgrid.

有一件事我可以thihk为重复的数据。在一些JSON字段我追加的原始数据之上的HTML。这是每个记录相同的HTML。现在看来似乎会更有效,如果我可以只发送数据,并在客户端上追加周围的HTML。这可能吗?然后,我也只是通过网络发送的实际数据,并在客户端的HTML标签的其余部分(的div等)加放在一起。

The one thing i can thihk of is Repeated data. In some of the json fields i am appending HTML on top of the raw "data". This is the same HTML on every record. It seems like it would be more efficient if i could just send the data and "append" the HTML around it on the client side. Is this possible? Then i would just be sending the actual data over the wire and have the client side add on the rest of the HTML tags (the divs, etc) be put together.

另外,如果有关于如何我可以最大限度地减少我的消息的大小任何其他建议,那将是巨大的。我想在某些时候,这些解决方案将增加客户端负载,但它可能是值得的,以减少网络流量。

Also, if there are any other suggestions on how i can minimize the size of my messages, that would be great. I guess at some point these solution will increase the client side load but it may be worth it to cut down on network traffic.

推荐答案

我同意克雷格斯顿茨:动态内容的HTTP的COM pression的使用是非常有效的。但非常有用的可还减少了其发送的数据。

I agree with Craig Stuntz: usage of HTTP Compression of Dynamic Content can be very effective. But very useful can be also reducing of data which are sent.

你应该没有时间HTML数据发送回的jqGrid第一。 jqGrid的有自定义格式(见的http:// www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter 并从<一个小例子href=\"http://stackoverflow.com/questions/2991267/jqgrid-editable-column-that-always-shows-a-select/2992064#2992064\">http://stackoverflow.com/questions/2991267/jqgrid-editable-column-that-always-shows-a-select/2992064#2992064)可用于填充&所述; TD方式&gt; 的jqGrid细胞元件的jqGrid数据的内部另外的html数据,如果要修改的网格数据非常糟糕。在这种情况下HTML数据应该被修改,并发送回服务器,所以最好的办法是从服务器的jqGrid发送纯数据并使用自定义格式格式化数据作为一个HTML片段。

First of all you should no time send HTML data back to jqGrid. jqGrid has custom formatter (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter and a small example from http://stackoverflow.com/questions/2991267/jqgrid-editable-column-that-always-shows-a-select/2992064#2992064) which can be used to fill <TD> elements of jqGrid cells. Moreover html data inside of jqGrid data are very bad if you want to modify grid data. In this case the html data should be modified and send back to the server. So the best way is sending pure data from the server to jqGrid and use custom formatter to format data as a html fragment.

在一般可以使用自定义格式去code或DECOM preSS的数据。例如,如果你在一个只列数据,如唧唧歪歪和哈哈有,你可以在唧唧歪歪和1送0而不是代替哈哈哈的。里面列的自定义格式的转换你0和1回唧唧歪歪和哈哈哈的字符串。如果您有一般性的重复数据这种做法是行不通的,但你可以使用next( jsonReader )的方式来代替。

In general you can use custom formatter to "decode" or "decompress" the data. For example, if you have in a column only data like "Bla Bla Bla" and "Ha Ha Ha", you can send 0 instead of "Bla Bla Bla" and 1 instead of "Ha Ha Ha". Inside of the custom formatter for the column you convert 0 and 1 back to the "Bla Bla Bla" and "Ha Ha Ha" strings. If you have general repeated data this approach will not work, but you can use the next (jsonReader) way instead.

有数据通信pression的另一种方式: jsonReader 的使用作为一个功能(见的​​http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#jsonreader_as_function和<一个href=\"http://stackoverflow.com/questions/2835957/jquery-with-asp-net-mvc-calling-ajax-enabled-web-service/2836817#2836817\">http://stackoverflow.com/questions/2835957/jquery-with-asp-net-mvc-calling-ajax-enabled-web-service/2836817#2836817)和 jsonmap 的使用(请参阅http://stackoverflow.com/questions/2690657/mapping-json-data-in-jqgrid/2706620#2706620例如),这也可以作为一个功能,这种技术是一个稍微复杂一些,但如果你在你的问题中添加您当前发送JSON数据的一个例子,jqGrid的定义的例子(尤其是 colModel ),我会写一个例子,你如何使用 jsonReader jsonmap 来COM preSS您的数据。

There are one more way of data compression: usage of jsonReader as a function (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#jsonreader_as_function and http://stackoverflow.com/questions/2835957/jquery-with-asp-net-mvc-calling-ajax-enabled-web-service/2836817#2836817) and usage of jsonmap (see http://stackoverflow.com/questions/2690657/mapping-json-data-in-jqgrid/2706620#2706620 for example), which can be also used as a function. This technique is a little more complex, but if you add in your question an example of JSON data which you send currently and the example of jqGrid definition (especially colModel) I will write an example how you can use jsonReader and jsonmap to compress your data.

更新时间::您code的一个地方,似乎对我很怀疑:

UPDATED: One place of your code seems to me very suspected:

Name = "<div class='showDescription' id= '" + i.id+ "'>" + i.Name + "</div>",

jqGrid的添加 ID 属性到网格行(&LT; TR&GT; 元素),但您添加手册同一个ID的&LT; D​​IV&GT;细胞内元素(&LT; TD&GT; 元素,这是孩子&LT; TR&GT; 元素)。这可以使你太大问题。一个HTML不允许有双重标识。

jqGrid add id attribute to the grid row (<tr> element), but you added manual the same id to the <div> element inside of cell (<td> element, which is child of the <tr> element). This can makes you much problems. A HTML not allowed to have a double ids.

对应您的主要问题,我可以写很多的一般建议如下:

Corresponds your main question I can write a lot of general recommendations like:


  • 这是更好地发送布尔值, 0 1 而不是来减少数据。

  • 如果你有你的网格内的ID数据,可以使用键列选项(见的 http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options )只能一次发送的值id您的JSON数据中。

  • 在最紧凑的形式传递日期值YY-M-D,并将其转换要在其中在客户端对于日期格式的文本形式。


  • it is better to send boolean as 0 or 1 instead of "true" and "false" to reduce the data.
  • if you have id data inside your grid you can use key column option (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options) to send id value only one time inside your JSON data.
  • transfer date values in the most compact form yy-m-d and convert it in the text form which you want on the client side with respect of date-formatter.
  • and so on

但可能你要首先解决您的具体应用程序中的主要性能问题。为了能够提高你应该张贴在你的问题你的解决方案的更多信息,您的特定应用程序:

but probably you want first of all to solve your main performance problem in your specific application. To be able to improve your specific application application you should post in your question more information about your solution:

  • jqGrid definition inclusive the full colModel definition (not like in http://stackoverflow.com/questions/3049052/long-delay-between-serverside-json-and-jqgrid-loadcomplete-on-asp-net-mvc-site)
  • a dump of data from paginatedData which you return as Json(paginatedData) or better your JSON data send to the client (you can copy the data from Fiddler http://www.fiddler2.com/fiddler2/ for example)
  • version information of jqGrid, jQuery and jQuery UI which you use
  • more information about your data model and database can be also helpful

如果没有这样的信息,你可以用你的赏金没有真正的好处给你。

Without this kind of information you can spend your bounty without real benefit for you.

更新2 :JSON数据优化的一个实际的例子,你可以找到<一个href=\"http://stackoverflow.com/questions/3054463/jqgrid-3-7-does-not-show-rows-in-internet-explorer\">http://stackoverflow.com/questions/3054463/jqgrid-3-7-does-not-show-rows-in-internet-explorer

UPDATED 2: A practical example of optimization of JSON data you can find in http://stackoverflow.com/questions/3054463/jqgrid-3-7-does-not-show-rows-in-internet-explorer

这篇关于什么是优化的一个asp.net MVC的网站我的JSON的最好方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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