In my opinion, there are several advantages on using JSON and render it client-side
- Payload: JSON is way smaller than HTML. Specially important if you are going to be browsed through a 3G connection. - Server optimization: usually, the server can render JSON faster than HTML (not in all cases, of course). - Extensibility: with a JSON API, you can consume it from devices that doesn't render HTML (or other HTML 'dialect', like a reduced version for mobile) - Testability: a JSON message is easy to test (you can easily mock the JSON for the client, for example) - I18N: it's easy to handle it in client-side, where you have all information about language and time settings. However, depending on how you transform that JSON into HTML in the page can destroy your client-side performance and your application architecture. The best solution is to choose a template system that works both in client-side and server-side (mustache, XSL,...). Then, let the client ask for a JSON response or a HTML rendered one. Then you can switch between both strategies depending on device, browser, connection speed... -- S.Cinos JavaScript Developer at youzee.com 2011/9/11 Poetro <[email protected]>: > 2011/9/11 Mo Cheng <[email protected]>: >> JSON might be more flexible. But, is HTML really more complex? >> Having related data as attribute started with "data-" is common practice to >> bind data to HTML >> <div data-id="xxx" data-foo="xxx" > >> ... >> </div> > > It is common, but parsing the DOM for some value is much costly then > parsing a JSON string, and you only need to do the parsing once, since > then it will be native. Although generating DOM from that JSON can be > costly, but that also needs to be done once. > > -- > Poetro > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/[email protected]/ > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/[email protected]/ > > To unsubscribe from this group, send email to > [email protected] > -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
