Fetching multiple queries at once with the Sanity client
Yes, absolutely! You can fetch all three queries at once using Promise.all(). This is much more efficient than awaiting each query sequentially because it runs them in parallel.
Here's how you'd rewrite your code:
const firstQuery = `*[groq here][]{}`;
const secondQuery = `*[groq here][]{}`;
const thirdQuery = `*[groq here][]{}`;
const [firstProp, secondProp, thirdProp] = await Promise.all([
sanityClient.fetch(firstQuery),
sanityClient.fetch(secondQuery),
sanityClient.fetch(thirdQuery)
]);
return {
props: {
firstProp,
secondProp,
thirdProp,
},
};This way, all three queries are sent to Sanity at the same time, and your code waits for all of them to complete together. Instead of taking (time for query 1) + (time for query 2) + (time for query 3), it takes roughly the time of your slowest query.
The performance improvement can be significant, especially if you have multiple queries or slower network conditions. Each fetch() call returns a Promise, and Promise.all() waits for all of them to resolve, then returns an array of results in the same order you passed them in.
This pattern works great with any of Sanity's client methods - whether you're in getStaticProps, getServerSideProps, server components, or anywhere else you're fetching data from Sanity. The Sanity client's fetch() method is designed to work seamlessly with standard JavaScript promise patterns like this.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.