Skip to main content

Concurrent Requests

Execute independent requests in parallel:
// ❌ Slow - sequential
const search = await sdk.search().execute({ query: 'ring' })
const collection = await sdk.collection({ handle: 'featured' }).execute()

// ✅ Fast - parallel
const [search, collection] = await Promise.all([
  sdk.search().execute({ query: 'ring' }),
  sdk.collection({ handle: 'featured' }).execute()
])
Call prepare and autocomplete concurrently for search-as-you-type:
const search = sdk.search()
const autocomplete = sdk.autocomplete()

const [prepareResult, autocompleteResult] = await Promise.all([
  search.prepare({ query: 'ring' }),
  autocomplete.execute('ring')
])

Prefetch Next Page

Prefetch the next page while the user views the current page:
const collection = sdk.collection({ handle: 'shirts' })

// Load current page
const page1 = await collection.execute({ page: 1 })

// Prefetch next page in background
collection.execute({ page: 2 })

Request Only Needed Attributes

Reduce response size by requesting only required attributes:
await collection.execute({
  params: {
    attributes: ['id', 'title', 'handle', 'images', 'price_range', 'available']
  }
})

Debouncing

The SDK handles debouncing automatically, but you can tune it:
// Faster response (more API calls)
const autocomplete = sdk.autocomplete({ debounceMs: 150 })

// Slower response (fewer API calls)
const autocomplete = sdk.autocomplete({ debounceMs: 500 })

Warm Cache on Page Load

Preload common queries on page load:
Promise.all([
  sdk.search().prepare({ query: 'ring' }),
  sdk.collection({ handle: 'featured' }).execute()
])

Next Steps