Search engines have improved so much over the years that it's commonly said that those who go all the way to page 3 are desperate ๐ . No, we're not talking about search engines today, we're talking about pages. As simple as they look, there are a few programming gymnastics that go into making them happen dynamically.
Back in the bad old days of web 1.0 ๐, the content on each page is hard-coded such that it's static. The content on page 1 is already written into the page, so is the content on page 2. It was somewhat straightforward and it got the job done back then. However, as the internet grew in size, features, and functionality, that had to change.
A relatable explanation
These days, the average netizen uses the web in a relatively unique way. What this means is that if you create content or interact with content online, a web app that's built to create a unique experience for you will end up curating relatively different things for you or dynamically returning content to you when you search for specific things.
By now you're starting to realize that if each page has static content, it's not possible to have a web app that's interactive or dynamic enough to provide you with a unique experience ๐ . Today we'll be looking at pagination. The name already gives it away so I guess the cat's out of the bag ๐.
Pagination basically refers to how we determine what content and how many units of content appear on a page. Without pagination, searches and content display wouldn't be user-friendly, pages would take much longer to load, and there'd be endless scrolling due to the fact that the website loads all the content on one page.
Proper Pagination Improves a Web App's Performance
By specifying how much content can fit into one page, the website works faster, is easier on the eyes, and netizens can scroll from the top of the page to the bottom in a matter of seconds. For companies that keep useful links and information at the very bottom of the page, this is very important.
Pagination can be implemented in several ways. There's the part that the average netizen sees; the page numbers are just aesthetics. While it fits into the scope of pagination, the real work is being done backend. The rule of thumb in development is to outsource as much of the complexity to the server and/or database as possible, as such pagination code instructions are implemented at the database level.
Finally
Recall that the database holds all the content of a website, and it's a lot faster and cleaner to implement instructions than to fetch much data and trim it at the application level. The key takeaways today are; pagination exists to regulate how much data is displayed on one page, and it's a lot better to implement pagination queries at the database level than at the application level.
A ton of my articles don't go into the how because I believe the major impediment for junior developers is the "what". Once you know that something exists, it's easier to learn. Be that as it may SQL Shack is a great place to learn pagination. This isn't a paid article, so you can be assured I'm only referring to them because they do justice to the "how" of pagination.