what is the best way to optimize my json on an asp.net-mvc site what is the best way to optimize my json on an asp.net-mvc site json json

what is the best way to optimize my json on an asp.net-mvc site


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.

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 jqGrid: Editable column that always shows a select) 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.

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.

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 jquery with ASP.NET MVC - calling ajax enabled web service) and usage of jsonmap (see Mapping JSON data in JQGrid 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.

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

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

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:

  • 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:

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

UPDATED 2: A practical example of optimization of JSON data you can find in Jqgrid 3.7 does not show rows in internet explorer


Set your server to ZIP responses. That will take care of the repeated data.


Going with your suggestion, if you want to append the html on the client side, check out jqgrid's Formatter:

http://www.secondpersonplural.ca/jqgriddocs/_2kn0mlo1p.htm

--

Also, while I'm guessing there's a Business reason for returning 200+ records per page, is server side pagination an option?