In an asp.net mvc3 view, I have a $.get() ajax call to a controller action which returns 80 lines of html code. Is it faster (from the .get call to finished rendering) to do the dom element creation on server side then just pass in one huge element to be appended to the DOM, or is it faster to just pass in a lot of raw data to the client side and then do all the DOM creation and appending there?
The html returned (or generated) creates a dashboard with about 5 layers of nested divs, some spans, text, etc.
I suggest you do your own benchmarks because this depends on a lot of factors, like your audience device (computer/mobile), internet speeds, data plan etc. Know your target audience first and do what’s better.
Returning formatted HTML is heavy on the traffic, but allows you to append it directly to the DOM. This is fine for people on a laptop/desktop who have broadband.
Returning raw data is faster but will make you create the DOM on the spot. However, this is usually ideal on high powered machines or mobile devices who have contracts whose payments are based on the amount of data transferred.