I'm kind of confused and was hoping one of you could give me some clarity. I am trying to get the best performance out of my Ajax request. The data coming across the wire is a 1,000 row 10 column table. The debate is: should I send Json or should I send Text? If I send Json, then doesn't that mean I have to include the column name for each item? Basically, the total size of the request will be increased by 10 x 1,000 in text inside the Json. Or, I can send a CSV across the wire and exclude the column names, thereby significantly reducing the size of the transfer. This has its own performance implications though, because then I have to parse the CSV on the client, rather than having it ready to go in Json. Thoughts anyone? Thanks
-
You don't need the keys/column names for json output, why would you think you do? Have you tried testing both ways yet? Questions about performance are better backed by numbers. More context would help as well (what the data is, what it's used for, how it is structured, etc.)No Results Found– No Results Found2013-09-11 03:23:43 +00:00Commented Sep 11, 2013 at 3:23
-
If your data is simple enough, you could do CSV, but if you gzip, I don't know if it'll make much difference. You seem to think that JSON doesn't need to be parsed. You're going to be parsing either way.user2736012– user27360122013-09-11 03:24:25 +00:00Commented Sep 11, 2013 at 3:24
-
So what exact problem are you solving? "Optimize something random" on the site?zerkms– zerkms2013-09-11 03:25:59 +00:00Commented Sep 11, 2013 at 3:25
Add a comment
|
1 Answer
What about just sending array of arrays inside JSON object like this and you won't have to parse CSV
{data: [ [a, a , a] , [ b, b, b] ] }
3 Comments
wayofthefuture
If I send an array of arrays, then I cannot acces the items by their names. I need them to be accessible by obj.name
Michael B.
According to your question, I understood that CSV is an option however you don't want the parsing. In that case, my suggestion would be somehow better.
Michael B.
You can save index for columns something like.. var columns = { id:0, name:1, price:2 } And for each row, you get column by row[i][ columns.id ]