How much data should one JSON call get?

When getting a list of elements through a json call, it is better to use several small calls (to get information as needed) or one big call with all the data.

For example, you have a json call to get a list of books matching a specific keyword. Only 100 results. You show data by page - 10 results per page. Is it efficient to make one call and get all the results or make a call for the next 10 on each page?

I would suggest that this is partially determined by the number of results. If this is some kind of huge number, the second option seems clear. But what is a good limit for the number that you can get in one call - 100, 1000, 10,000 points?

+6
source share
2 answers

It depends.

Obviously, you want to reduce bandwidth usage to a minimum, but there is also overhead for each individual call. You have to make some reasonable guesses, and most importantly: how likely is it that you will need data from pages 2 to 100?

If this is very likely (say, in 90% of cases, users will click on several pages of the same result set), then I would load the whole result at a time, but otherwise I would load separate pages in the process.

Another thing to keep in mind is latency. Each ajax call has a certain delay, depending on the distance (in the network topology, not necessarily geographical) between the client and server. Latency is inevitable for the first load, but after that you need to ask yourself if a quick response is important. Under normal circumstances, this is expected and acceptable, but if your typical use case involves repeatedly flipping between pages, this can be a nuisance, and you might consider buying an attachment for a longer initial loading time.

If you want to load several pages, but the result set is too large (say, thousands or millions of pages), you can think of more complex schemes, for example, load the requested page and the next 10 or load the requested page, and then pre-select the next 10 pages in background mode.

0
source

Generally, every ajax call has overhead and reduces the number of different calls, makes performance better .. if the data is not big ...

In paging, it’s usually better not to retrieve all the data from the very beginning, because usually users don’t move across all pages .. so you can reduce the load on the server without moving the data ... on the other hand, if the data is relatively small or you think that the user will need to see all the data, extract it to save the overhead for various calls ...

+1
source

Source: https://habr.com/ru/post/898886/


All Articles