Pagination methods
ButterCMS offers two pagination approaches, each suited to different use cases. These methods are mutually exclusive - use one or the other, not both.Page-based pagination
Page-based pagination is the most common approach and is ideal for traditional “page 1, page 2, page 3” navigation patterns. Parameters:page- Page number (default: 1, minimum: 1)page_size- Number of items per page (default: 10, minimum: 1, maximum: 100)
Offset-based pagination
Offset-based pagination is ideal for infinite scroll implementations and more flexible navigation patterns. Parameters:limit- Maximum number of items to return (default: 10, minimum: 1, maximum: 100)offset- Number of items to skip before returning results (default: 0, minimum: 0)
Choosing the right pagination method
| Use Case | Recommended Method | Reason |
|---|---|---|
| Traditional page navigation | Page-based | Intuitive “Page X of Y” display |
| Infinite scroll | Offset-based | Easy to append new items |
| Load more button | Offset-based | Simple offset increment |
| SEO-friendly archives | Page-based | Predictable, crawlable URLs |
| Random access to pages | Page-based | Direct page number access |
Filtering paginated results
To filter by author, category, tags, or custom field values, see Filtering Requests.Combining pagination and filtering
Performance tips for pagination
Choose appropriate page sizes
Choose appropriate page sizes
- 10-25 items is optimal for most use cases
- Larger page sizes increase response time and payload
- Smaller page sizes (under 10) may require excessive requests for large content sets
- Consider your content type: text-heavy items warrant smaller pages
Always use exclude_body for listings
Always use exclude_body for listings
For blog post listings, always include See Query Optimization for more on
exclude_body=true:exclude_body and levels.Cache paginated results
Cache paginated results
Implement client-side or server-side caching for paginated results: