Pagination using vanilla javascript

What is the most reliable way to create Pagination using vanilla javascript or some plugin?

There are two methods of creating pagination:

  1. Server-side pagination, when you only ask for, let’s say, 10 articles from your database and also requiring COUNT() - the total amount of articles. In this case you would need to let server know, what page are you on, normally with the query string in the request, like ?page=13. PRO of this approach, that you have very small, controlled payloads from server
  2. Fake aka front-end pagination, when you fetch every article and then filter this whole array on the front. PRO of this approach that user needs to suffer huge payload just once and then navigation through the pages is lightning fast - basically I would even do 80-160ms delay on purpose to show that content is “loaded”, this will make it look more natural.
1 Like

It all depends on the COUNT(), if it’s Instagram feed or something that potentially might scale up - forget about the second method

Thanks alot, handy explication that makes a ton of sense, thanks.