Possible Duplicate:
Why is it a bad practice to return generated HTML instead of JSON? Or is it?
IF I send an AJAX request to a PHP file, what would result in faster rendering of HTML:
- Sending the completely formatted HTML straight from PHP, or:
- Just send JSON data and let Javascript do the HTML rendering?
I have a rather complex HTML structure, and this puts download time of a large HTML chunk vs. the times Javascript (jQuery) needs to render the same structure.
Is there even a conclusive answer?
JSON is the way to go. Network can be huge bottleneck while javascript is fast at handling things. The greatest difference will be on slow connections. And it definitely worth the parsing. New browsers offer native JSON, so it should be crazy fast.
One more thing to consider: innerHTML has a lot of bugs (tables, forms, etc.). In those cases you have do a lot of overhead in order to get it work cross-browser. Problems may arise unexpectedly, which makes your application less stable.
JSON, however, let you decide if you want to use innerHTML or DOM methods according to the content. This is another huge win.