Let's say I want to lazy load comments on a blog, such that only the 10 newest ones are shown initially, and the next batch of 10 is lazy loaded on scroll.
Option A: send the entire array of results from the server on page load, and handle rendering 10 at a time client side.
Option B: load 10 on page load and send ajax requests for 10 more as needed.
Suppose the number of objects can reach 40,000 - is it ok to send such a large json array to the client on page load?
I see the trade-offs as: with Option A, you minimize trips to the database, but you send potentially too much data to the client (a 40,000 record json array ≅ 7mb), which is not ideal for mobile users. With option B, you may have too many trips to the database.
Is there a best practice on this? Maybe compromise somewhere in the middle? That is, eager load 200 objects to the client, only rendering 10 initially and rendering 10 more until then 200 objects are used up, and then lazy load from the server as needed? Wanted to see how others are addressing this.