Caching & URLs
headquery only sends GET requests for reads, and the same logical query always produces
the same URL, regardless of the order in which you call the builder methods:
- query keys are sorted
undefined/nullvalues are dropped- arrays are joined with
,in the given order (order matters, e.g. forsort) [,],:and,stay unencoded for readability
So browsers, CDNs and reverse proxies can cache CMS responses without any extra setup.
Using the URL as a cache key
Every query exposes its full URL without sending a request:
const = .("blog").("featured", true).(3);
.();
// https://cms.example.com/api/collections/blog/entries?filter[featured:is]=true&limit=3Use it as the key for SWR, TanStack Query, Nuxt’s useFetch, or your own cache. See
Data fetching libraries for TanStack Query and SWR, and
Next.js and Nuxt for framework-specific setups.
Framework fetch options
fetchOptions is passed through to fetch, including framework-specific keys:
// Next.js: revalidate CMS data every 60 seconds
const = ({
: "https://cms.example.com",
: { : { : 60 } },
});
// or per call
await .("settings").({ : { : "no-store" } });Last updated on