Skip to main content

Key optimization parameters

1. The exclude_body parameter

The exclude_body=true parameter reduces response size by 50-70% for blog post listing operations. This is one of the most impactful optimizations you can make. When to Use:
  • Blog post listing pages
  • Archive pages
  • Search results
  • RSS feed generation
  • Related posts widgets
When NOT to Use:
  • Individual post pages (you need the body)
  • Full-text search implementations
  • Content that displays the full article
Example:

2. The levels parameter

The levels parameter controls reference field depth in API responses, balancing data completeness with response size and performance. Configuration:
  • Default: levels=2 covers most page display scenarios
  • Range: 1-5 (values outside this range are automatically adjusted)
  • Level 1: Reference fields return API URIs only (minimal data transfer)
  • Level 2+: Reference fields return complete object data
  • Level 5 (max): Returns URIs for any remaining references beyond specified depth
Level Comparison:
Recommended Usage:

3. Field filtering

Filter content server-side to fetch only what you need — by author, category, tag, or any custom field value. See Filtering Requests for the full reference with examples for blog posts, pages, and collections.

4. Ordering

Order results server-side instead of sorting client-side: Available Order Fields:
  • published - Publication date
  • updated - Last update date
  • Custom content fields
Order Direction:
  • Ascending (default): order=published
  • Descending: order=-published (prepend -)
Examples:

5. Pagination

Use appropriate page sizes and pagination methods to avoid oversized responses. The recommended range is 10-25 items per request for optimal performance.

Pagination

Page-based and offset-based pagination, infinite scroll, and archive page patterns

Filtering Requests

Filter by author, category, tag, and custom field values

Serialization performance

When cached content is unavailable (cache miss), the API must serialize both the requested content and all content referenced at the specified depth. For list endpoints, this increases processing time significantly. Example Problem: Requesting 100 pages with levels=2 may require serializing 100+ individual objects plus their references. Recommendation: Always use levels=1 for list operations, then fetch full details for individual items when needed.

Query optimization patterns

Pattern 1: two-stage fetching

Fetch lists with minimal data, then fetch full details on demand:

Pattern 2: parallel requests

Fetch independent data in parallel:

Pattern 3: selective field loading

Only request the data you need for each view:

Pattern 4: caching query results

Cache optimized query results for repeated access:

Response size optimization

10MB Response Limit: ButterCMS has a 10MB response size limit. If your queries approach this limit, reduce levels or page_size.

Estimating response sizes

Size reduction strategies

  1. Use exclude_body=true for all listing endpoints
  2. Use levels=1 for navigation and lists
  3. Limit page_size to 10-25 items
  4. Filter server-side instead of fetching everything

Search optimization

When using the search endpoint, keep these optimizations in mind: Search Limitations:
  • Only the direct content of pages is searched
  • References are excluded from search but appear in results
  • Maximum query length: 100 characters
Optimized Search Implementation:

Query optimization checklist

  • Identify the minimum data needed for each view
  • Plan which endpoints to use for each feature
  • Consider caching strategy for each query type
  • Use exclude_body=true for all blog listings
  • Set appropriate levels (default to 1 for lists)
  • Use server-side filtering instead of client-side
  • Order results server-side with order parameter
  • Implement parallel fetching for independent data
  • Measure response times with real data volumes
  • Test with cache cold and warm states
  • Monitor response sizes stay well under 10MB
  • Verify minimal data for each view type