I’m writing a database app, that is going to pull out some data and display it on a web browser or mobile app. Is it better to format the data on the server end before replying to the AJAX command or let the browser/mobile app format the data on the browser end to the screen.
Take a simple ordered list
<OL>
<LI>Number 1</LI>
<LI>Number 2</LI>
<LI> ....</LI>
</OL>
I can either sent a json (my format is just an example not real JSON data) array back with just the data and let the far end format it requiring more processing on the far end
a[0]Number1;a[1]Number 2;a[3]....
or I can send back where its formatted on the server, and the far end just displays it, less processing
a[0]<OL>;a[1]<LI>Number 1</LI>;a[3]<LI>Number 2</LI>;a[4]<LI>....</LI>;a[5]</OL>
Just looking for +/- reasons to do one vs the other.
Thanks
/Andy
I would recommend that your service calls return JSON and that you avoid returning HTML. Depending on how much data your AJAX call returns the performance hit may be negligible but it is bad form and reduces the reusability of your service.
To avoid choppiness while creating your list on the client side, add tags and formatting in a temporary variable and add the entire structure to the DOM at once.