Search code examples
jqueryclient-side-data

What is the best practice for passing large amounts of client side data to the server?


I have a lot of data on the client side made up of mostly large arrays and I need to get this info back to the server and be able to parse it easily. I'm using jQuery on the front end and PHP (CodeIgniter) on the back end.

Right now I'm just POSTing one huge array using jQuery $.post. Is this a good idea or should I use several smaller ones?

Also, should I be using jQuery's ajax methods or is there something better than this?


Solution

  • If you can combine all the data into one post, that's definitely the way to go. Browsers, most notably IE (gag), will choke when you exceed too many simultaneous XHRequests to the same server. Too many at a time generally means more than 2.

    Basically, best practice for sending data to the server can be summed up as: "as little as possible in as few requests as possible". How you strucutre the data is up to you.

    If you're really sending a lot via jQuery, consider compressing it with something like jsend (a jQuery plugin to compress, with a PHP counterpart to decompress).