Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does json add any overhead compared to returning raw html?

I have a ajax call that is currently returning raw html that I inject into the page.

Now my issue is, that in some situations, I need to return back a count value along with the raw html, and if that count is > 10, I need to fire another jquery operation to make something visible.

The best approach here would be to return json then right? So I can do:

jsonReturned.counter
jsonReturned.html

Do you agree?

Also, out of curiosity more than anything, is json any more expensive performance wise? It is just a simple object with properties but just asking.

like image 771
Blankman Avatar asked Mar 17 '26 11:03

Blankman


1 Answers

This question reserves some discretion, but in my opinion, there is no efficiency concern with returning JSON instead of raw HTML. As you stated, you can easily return multiple messages without the need for extra parsing (I'll often have a status, a message, and data for example).

I haven't run any numbers, but I can tell you I've used JSON via AJAX in very heavy traffic (millions of requests) situations with no efficiency concerns.

like image 65
dtbarne Avatar answered Mar 20 '26 06:03

dtbarne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!