Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice: loading rendered html or json?

Tags:

json

html

ajax

Hey folks, I have a question which feels stupid but I can't quite say why.

Background:

Imagine a webapp with users and tags. Users tag each other.

I've got one page in the app which displays details about a single tag in relation to a single user. Let's say user 'bob' and tag 'footag'. On this page, I'm displaying two lists: all the people who have tagged bob with 'footag' and all the people bob has tagged 'footag'. let's call these <div id="received'> and <div id="sent">

Let's say the url for this view is /users/bob/tags/footag

Naturally, these lists are long -- I don't want to load the whole list upon pageview. So I load the first ten for each.

The question

Now I can provide dynamic paging for each of the lists in one of two ways:

  1. Get the data for the next 10 users as json. Write js to render this data, replacing the contents of the div.
  2. Get a rendered "snippet" of html from another well defined URL on my server, say /users/bob/tags/footag/received?page=1. I fetch it asynchronously and just replace the contents of the relevant <div>.

So in one case I fetch data and render it via JS in the browser, the other I fetch rendered data and just plonk it wholesale into the document.

Is there any reason not to use #2? I can't imagine one but I suppose there might be security aspects I'm not considering, or performance, or something else. I'd much prefer to do #2 as it simplifies my life significantly.

Thanks!

like image 280
Idan Gazit Avatar asked Jul 17 '09 20:07

Idan Gazit


People also ask

What is fully rendered HTML?

Rendered HTML is the HTML structure that exists in the client browser after loading a page has entirely completed, including processes that manipulate the original HTML sent from the server.

What is http rendering?

Rendering is a process used in web development that turns website code into the interactive pages users see when they visit a website. The term generally refers to the use of HTML, CSS, and JavaScript codes. The process is completed by a rendering engine, the software used by a web browser to render a web page.

What is a rendered page?

What does webpage rendering mean? Rendering a webpage is the process of turning HTML, CSS, and JavaScript code into an interactive page that website visitors expect to see when clicking on a link. Every website page is designed with the end user in mind.

What is rendering in UI?

What is "rendering"? Ultimately, it is a process of displaying data in a UI component. Suppose the component is drop-down list displaying some items. Rendering and re-rendering of the drop-down list will force the component to update its contents.


2 Answers

I've got an app like this -- I use both methods.

I use your Method #1 to update fields that aren't contiguous (e.g. input fields all over the place), but I use your Method #2 to update tabular data, kind of like your lists.

I would stick to #2 for your case.

like image 185
Cᴏʀʏ Avatar answered Sep 21 '22 19:09

Cᴏʀʏ


i'd go with #1 ... so you really get the data, not just some HTML ... it will simply be a concise JavaScript object structure and not some string, so you can evaluate the data at will, cache it, use it for searches, etc. ... the more work is done on the client side, and the cleverer it is, the better you app scales ... you have 1 server, or maybe 2-10, or i don't know, but you have 10-10000 more clients ...

greetz

back2dos

like image 22
back2dos Avatar answered Sep 23 '22 19:09

back2dos