[cgiapp] Ajax app using CAP -- return JSON or HTML?
Ron Savage
ron at savage.net.au
Sat May 24 22:54:55 EDT 2008
Hi Mark
> I'm at a crossroad:
> should the CAP-based back-end normally return
> JSON data (and let the javascript library (I've decided on jQuery)
> place and format the data on the page),
> or should the back-end normally return
> HTML (via html templates), which will be dropped into different, say, <div>s?
> (BTW, I'm not considering XML.)
My policy is to put as much code as possible into a single language, so
I'd do the work on the server side.
> It seems like the road I take will have a signficant impact on
> implementation, and maybe maintainability, etc. so I'd like to go
> down the better road, if there is one.
>
> Thinking out loud here... with JSON, I see these advantages:
> - the back-end will just return data, not (HTML) document structure
> - I can more easily target multiple areas of the page with a single
> AJAX call (with jQuery, I don't think it is easy to target multiple
> DOM elements if I return HTML)
> - it will probably be easier to add visual effects to certain DOM
If you use CSS it presumably would not advantage one way over the other.
> elements as I'm converting JSON to HTML (vs. hunting through the
> returned HTML for specific elements... hmm, that would require changes
> to both the back-end and the javascript -- yuck)
How about listing the disadvantages? Perhaps that will tell you
something.
For instance, a disadvantage of JSON would be the fact you'd have to
ship more code from the server to the client to do the processing on the
client side. Why do that at all?
> With HTML I see these advantages:
> - less javascript to write
> - the HTML can be put into templates (so the back-end logic is still
> pretty much isolated from (HTML) structure), and it may be easier to
> manage HTML template files, vs. one large javascript file
Or to put it slightly differently, 'it may be easier to manage /multiple, small/ HTML template files'.
--
Ron Savage
ron at savage.net.au
http://savage.net.au/index.html
More information about the cgiapp
mailing list