Why is it a bad practice to return generated HTML instead of JSON? Or is it?

Viewed 66560

It is quite easy to load HTML content from your custom URLs/Web services using JQuery or any other similar framework. I've used this approach many times and till now and found the performance satisfactory.

But all the books, all the experts are trying to get me to use JSON instead of generated HTML. How's it much more superior than HTML?

Is it very much faster?
Does it have a very much lesser load on the server?

On the other side I have some reasons for using generated HTML.

  1. It's simple markup, and often just as compact or actually more compact than JSON.
  2. It's less error prone cause all you're getting is markup, and no code.
  3. It will be faster to program in most cases cause you won't have to write code separately for the client end.

Which side are you on and why?

14 Answers

I think it depends on the structure of the design, it's just more sexy to use JSON than HTML but the question is how would one handle it so it can be easily to maintain.

For example, say I have the listing page that utilize the same html/style of the entire site, I would write the global function to format those portions of HTML and all I have to do is passing the JSON object into the function.

Depends on the circumstances.

Sometimes it is essential to avoid JSON. When our programmers have trouble programming in js, for example.

My experience tells me that: better use ajax service than inline JSON.

Sooner or later the js becomes a problem

Related