Client-Side vs Server-Side Pagination in JavaScript
Two approaches to pagination. Here is when to use each and how to implement them.
Client-Side vs Server-Side Pagination in JavaScript
There are two approaches to pagination. Here is when to use each.
Client-Side Pagination
All data is loaded upfront. The browser slices the data for each page.
const allData = [...]; // 100 items loaded const pageSize = 10; function getPageData(page) { const start = (page - 1) * pageSize; return allData.slice(start, start + pageSize); }
Pros: fast page switches (no network), simple to implement, works offline. Cons: slow initial load (all data at once), high memory usage, not suitable for large datasets.
Use for: small datasets (< 1000 items), static data, offline apps.
Server-Side Pagination
Each page is fetched from the server on demand.
async function getPageData(page, size) { const res = await fetch(`/api/data?page=${page}&size=${size}`); const { data, total } = await res.json(); return { data, totalPages: Math.ceil(total / size) }; }
Pros: fast initial load (only one page), low memory, scalable to millions of items. Cons: network latency on page switch, more complex (server needs to support pagination).
Use for: large datasets (> 1000 items), databases, APIs.
When to Use Which
| Feature | Client-Side | Server-Side |
|---|---|---|
| Dataset size | Small (< 1000) | Large (> 1000) |
| Initial load | Slow (all data) | Fast (one page) |
| Page switch | Instant | Network delay |
| Memory | High | Low |
| Complexity | Simple | More complex |
| Scalability | Limited | High |
The Takeaway
Client-side: load all data, slice with array.slice. Fast page switches but slow initial load. Good for small datasets. Server-side: fetch one page at a time from the API. Fast initial load but network delay on page switch. Good for large datasets. Choose based on your dataset size.
Client-side: load all data upfront, slice with array.slice in the browser. Fast page switches, slow initial load, high memory. Server-side: fetch one page at a time from the API. Fast initial load, network delay on page switch, low memory.
For large datasets (> 1000 items). Server-side fetches only the current page, so the initial load is fast and memory is low. It scales to millions of items. The tradeoff is network latency on each page switch.
For small datasets (< 1000 items). Client-side loads all data at once, so page switches are instant (just array.slice). The tradeoff is a slow initial load and high memory. Good for static data or offline apps.
Fetch the current page from the API: const res = await fetch(`/api/data?page=${page}&size=${size}`); const { data, total } = await res.json(). Calculate totalPages: Math.ceil(total / size). Render the data and pagination controls.
Load all data upfront. Slice for the current page: const start = (page - 1) * pageSize; const pageData = allData.slice(start, start + pageSize). Calculate totalPages: Math.ceil(allData.length / pageSize). Render and paginate instantly.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

