Performance: Pagination patterns
MEDIUM IMPACT
Pagination patterns affect how quickly data loads and renders on the page, impacting load speed and interaction responsiveness.
from fastapi import FastAPI, Query app = FastAPI() @app.get('/items') async def read_items(page: int = Query(1, ge=1), size: int = Query(10, ge=1, le=100)): # Returns only a page of items offset = (page - 1) * size return get_items_from_db(offset=offset, limit=size)
from fastapi import FastAPI app = FastAPI() @app.get('/items') async def read_items(): # Returns all items at once return get_all_items_from_db()
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Load all data at once | High (all items in DOM) | Many reflows | High paint cost | [X] Bad |
| Server-side pagination | Low (page items only) | Single reflow | Low paint cost | [OK] Good |
| Client-side pagination with all data | High (all items in DOM) | Many reflows | High paint cost | [X] Bad |
| Client-side pagination with page data | Low (page items only) | Single reflow | Low paint cost | [OK] Good |