Pagination: Server Side or Client Side?

前端 未结 9 2021
生来不讨喜
生来不讨喜 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:20

    The right answer depends on your priorities and the size of the data set to be paginated.

    Server side pagination is best for:

    • Large data set
    • Faster initial page load
    • Accessibility for those not running javascript

    Client side pagination is best for:

    • Small data set
    • Faster subsequent page loads

    So if you're paginating for primarily cosmetic reasons, it makes more sense to handle it client side. And if you're paginating to reduce initial load time, server side is the obvious choice.

    Of course, client side's advantage on subsequent page load times diminishes if you utilize Ajax to load subsequent pages.

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

    Doing it on client side will make your user download all the data at first which might not be needed, and will remove the primary benefit of pagination.

    The best way to do so for such kind of AJAX apps is to make AJAX call the server for next page and add update the current page using client side script.

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

    Do you mean that your JavaScript has all the data in memory, and shows one page a time? Or that it downloads each page from the server as it's needed, using AJAX?

    If it's the latter, you also may need to think about sorting. If you sort using JavaScript, you'll only be able to sort one page at a time, which doesn't make much sense. So your sorting should be done on the server.

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