Pagination: Server Side or Client Side?

前端 未结 9 2019
生来不讨喜
生来不讨喜 2020-11-29 18:39

What is it best to handle pagination? Server side or doing it dynamically using javascript?

I\'m working on a project which is heavy on the ajax and pulling in data

相关标签:
9条回答
  • 2020-11-29 19:08

    Server side - send to the client just enough content for the current view.

    0 讨论(0)
  • 2020-11-29 19:10

    Even with small data sizes the best choice would be server side pagination. You will not have to worry later if your web application scales further.

    And for larger data sizes the answer is obvious.

    0 讨论(0)
  • 2020-11-29 19:10

    In a practical world of limits, I would page on the server side to conserve all the resources associated with sending the data. Also, the server needs to protect itself from a malicious/malfunctioning client asking for a HUGE page.

    Once that code is happily chugging along, I would add "smarts" to the client to get the "next" and "previous" page and hold that in memory. When the user pages to the next page, update your cache.

    If the client software does this sort of page caching, do consider how fast your data ages (is likely to change) and if you should check that your cached page of data is still valid. Maybe re-request it if it ages more than 2 minutes. Maybe have a "dirty" flag in it. Something like that. Hope you find this helpful. :)

    0 讨论(0)
  • 2020-11-29 19:11

    One other thing to point out here is that very rarely will you be limited to simply paging through a raw dataset.

    You might have to search for certain terms in one or more columns you are displaying, and then say sort on a few columns and then give the users the ability to page through this filtered dataset.

    In a situation like this you might have to see whether it would be better to have this logic search and/or sort client side or server side.

    Another thing to consider is that Amazon's cloud search api gives you some very powerful searching abilities and obviously you'll want to allow cloud search to handle searching and sorting for you if you happen to have your data hosted there.

    0 讨论(0)
  • 2020-11-29 19:12

    If you have large pages and a large number of pages you are better of requesting pages in chunks from the server via AJAX. So let the server do the pagination, based of your request URL.

    You can also pre-fetch the next few pages the user will likely view to make the interface seem more responsive.

    If there are only few pages, grabbing it all up-front and paginating on the client may be a better choice.

    0 讨论(0)
  • 2020-11-29 19:19

    I prefer server side pagination. However, when implementing it, you need to make sure that you're optimizing your SQL properly. For instance, I believe in MySQL, if you use the LIMIT option it doesn't use the index so you need to rewrite your sql to use the index properly.

    G-Man

    0 讨论(0)
提交回复
热议问题