简体   繁体   中英

How many items in REST/JSON response before switching to server-side paging

I am trying to determine the number of items at which I stop client side data loads from a REST call and switch to server-side paging. Is this more a matter of watching the performance or do others follow a rule of thumb such as "if more than 1000 items returned in a response, switch to using server-side paging".

The reason I am torn is that I am also using sorting on a list of data, and if I load, for example, all 1000 items... it can sort across the 1000 items... but if I use server-side paging in which I return 10 items at a time, I can only sort within the 10 items, so that if I go the 2nd page of results, it does not take the entire list of 1000 items into consideration since it is only returning 10 at a time.

You should care more about the size of the JSON request as opposed to how many items. For instance, if your item is only a character then 1000 characters is miniscule but if your item is a massive document then you may have a problem.

The point at which you need to be aware of is when a full page reload becomes faster than an AJAX request. You can do some simple profiling by using your browsers dev tools to get a rough idea.

Since you're using a RESTful API, one solution may be to send the primary ID of an item and something like a name when the browser makes the 1000 item index call. Then you can use the primary ID to link to the full item.

Another solution may be to implement your pagination with AJAX. You can avoid multiple full page loads this way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM