What is the best and faster way to transfer a DataTable from server side to client side: using JSON format or pure HTML?
Asked by
Ranimi23 (
1917)
June 27th, 2010
This is a one big problem with using AJAX, how to move the data that need to be update from the server side to the client side:
I have tried both ways and I can see that pure HTML is faster, don’t know why yet. It seems like transfering pure HTML and in client side doing innerHTML with JavaScript is working better.
Although, translating the data into JSON format and transfering it to client is maybe a better solution for reading the data and building the HTML on the client side with JavaScript and not in the server.
What do you think? I’m looking for the FASTEST way, a better performance for web 2.0 application.
Observing members:
0
Composing members:
0
9 Answers
Unless there is a good reason to write the displayed data cient side, pure HTML should be more efficient. It should display in a browser faster. Also, the server side source code is visible to all search spiders, whereas HTML generated client side will not be visible to any bot that does not have a JavaScript interpreter.
Thank you! This is very intersting issue, I did thoght that making the HTML on the Server side means more time for the connection between client ans server, which means more time it’s busy.
I must say, I don’t like the JSON format. It has lots of problem with content that has strings with quotation marks, commas, dashes and more.
I am looking for the fastest way to deliver DataTable from server to user and display it in AJAX.
For GET requests I prefer to encode in JSON on the server (PHP would be: json_encode($data);) as the size of the data being sent is much smaller encoded in JSON than HTML, then simply use JavaScript to decode the JSON back into HTML to display. No matter which way you look at it, its faster to transfer 7kb (because the data is serialized and extra characters such as spaces, which do take up space, have been removed) to the user than say 100kb.
JQuery has some great tools for this. You can reduce the size of the data being sent significantly which will increase the speed of the request.
Also if you are concerned about how the AJAX will effect your spidering, Google suggests using a text browser such as Lynx (http://lynx.isc.org/) to simulate how the spider will read your page. If important content is not being displayed in that, you may want to re-think how your displaying your information, whether to use AJAX or not.
BTW – Is there a problem with SEO if the HTML is being made on client side only? So I need to have a copy of my pages?
I would assume it would only be a problem if the spider is unable to see the text if it cant parse the javascript. So if the html renders fine in the lynx browser you should be good to go, and the spider will pick it up.
I think I will do all the HTML string in server and send it to the client for innerHTML and that’s it. It is also easier for doing than using JSON and more.
Good luck with it. Give us a pointer to it to take a look when you get it online.
Answer this question
This question is in the General Section. Responses must be helpful and on-topic.