Sanity provides two APIs:
- The live, uncached API is the default and will always give you the freshest data. The downside of using it is that requests will be slightly slower because they need to reach our backend on every request. Requests are also more costly, because they will trigger more computation on our servers.
- The CDN-distributed, cached API, which is an opt-in feature that will give you very fast responses to requests that have been cached. We encourage most users to use this API for their front-ends unless there is a good reason not to. The API CDN currently caches requests for 15 seconds.
To use the CDN API, simply use
apicdn.sanity.io instead of
api.sanity.io. Most clients provide a
useCdn option that makes this switch seamless.
There are a couple of scenarios where the API CDN cannot be used:
- When a mutation is performed (creating/editing/deleting documents)
- When listeners are used (subscribing to changes)
- When requests are authenticated using an access token or cookie.
All official clients will automatically fall back to using the live API in these.