[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: hmm.png (42 KB, 1024x1024)
42 KB
42 KB PNG
When using Ajax for the purpose of rerendering a portion of a page with new data, is it better for:

A. The endpoint to respond with HTML, which would use more bandwidth but would be able to be inserted into the page immediately

or

B. The endpoint to respond with JSON, which would use less bandwidth but would require HTML to be constructed on the browser
>>
>>108543477
network bandwidth is an expensive IO comparatively so just send the json data
>>
>>108543477
Whatever is easiest, it's probably a matter of just 2 vs 3 KB so it's negligible
>>
>>108543499
What about the fact that the JS file sent to the browser would be bigger since it would need to contain more code?
>>
>>108543549
What about it? Please tell us, we're all waiting your underage retarded opinion
>>
>>108543477
XML or XHTML
I refuse to elaborate any further
>>
Ajax tongues my anus. Don't do it.
>>
>>108543477
Depends how big the HTML is
https://endtimes.dev/why-your-website-should-be-under-14kb-in-size/
>>
>>108543477
As a matter of fact, Rails' ActionCable does point A. It can work if you're not doing very massive page renders but for more complex scenarios, I would definitely prefer B.

https://www.cloudbees.com/blog/actioncable-the-missing-guide#partial-content-reloading
>>
>>108543477
>I'm going to do client html rendering, for performance!
>To do this, I need to server render some json
now you have two problems, as they say
>>
>>108543477
If you have to do lots of document.createElement() calls, then return HTML - it's easier to manage the UI. If you're just updating a few data points and don't need to do any DOM manipulations(except e.g element.innerText = ....) then return JSON.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.