I need to transfer a large amount of data from server to client and then, with JavaScript (jQuery) generate a lot of tables, divs and other know and unknown html elements .
When I was trying to generate those tables and divs on client side a had a couple of for loops and I was creating and appending elements on the fly.
I soon discovered that it takes a lot of time to generate all those elements and show them so I generate HTML on server side with HtmlTextWriter then I convert it ToString() and append that string on client side.
It is much faster but it is “seljacki” as we would call it in my language (the closest translation is “not elegant solution”).
So I wanted to ask does anyone have some more elegant solution to suggest and is this method that I’m using completely wrong or it could pass?
Thanks to everyone.
You don’t show your code here, but I’d guess that in your loop you are repeatedly appending rows to a table or whatnot as you iterate through the results. If so, the bottleneck is not actually generating the HTML but redrawing the content each iteration. Try assembling the entire HTML to add in memory first, then use a single
append()orhtml()call to update the document.