简体   繁体   English

切换到服务器端分页之前,REST / JSON中有多少项响应

[英]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. 我试图确定从REST调用停止客户端数据加载并切换到服务器端分页的项目数。 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". 这更多是看性能问题还是其他人遵循经验法则,例如“如果响应中返回了1000多个项目,则切换到使用服务器端分页”。

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. 我被撕裂的原因是我也在对数据列表进行排序,例如,如果我加载所有1000个项目...它可以跨1000个项目进行排序...但是如果我使用服务器端分页其中一次返回10个项目,我只能对10个项目进行排序,因此,如果我进入结果的第二页,则不会考虑1000个项目的整个列表,因为它一次只能返回10个项目时间。

You should care more about the size of the JSON request as opposed to how many items. 您应该更关心JSON请求的大小,而不是关注多少个项目。 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. 例如,如果您的项目只是一个字符,那么1000个字符就很小了,但是如果您的项目是一个庞大的文档,那么您可能会遇到问题。

The point at which you need to be aware of is when a full page reload becomes faster than an AJAX request. 您需要注意的一点是,整页重新加载的速度快于AJAX请求的速度。 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. 由于您使用的是RESTful API,一种解决方案可能是在浏览器进行1000个项目索引调用时发送项目的主ID和类似名称的名称。 Then you can use the primary ID to link to the full item. 然后,您可以使用主要ID链接到完整项目。

Another solution may be to implement your pagination with AJAX. 另一个解决方案可能是使用AJAX实现分页。 You can avoid multiple full page loads this way. 您可以通过这种方式避免多次加载整个页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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