Astro

Content layer

Content layer is Astro's loader-based system for bringing content into collections from files, a CMS, or an API. It stores results in a local cache so builds stay fast.

How it is measured

Each collection names a loader. glob and file read local files, and a custom loader can fetch from a remote API. Astro writes loaded entries to a data store in the .astro folder and reuses unchanged ones.

Check by timing two builds in a row. The second should skip unchanged entries. Clear the cache folder and the next build should load everything again.

Worked example

A bookstore pulls 3,800 titles from a headless CMS using a custom loader. The first build takes 94 seconds. A second build with 12 changed entries finishes in 11 seconds because the store keeps the rest.

A price edit in the CMS needs the loader to refetch. The team runs a scheduled build every hour rather than keeping stale data for days.

How it differs

The content layer is the loading engine. Content collections are the typed groups you query after loading. The layer excludes the schema and queries; collections exclude where the data came from.

Common errors

Assuming the dev server polls the remote source. Forgetting to set the schema on remote data. Loading secrets into the data store. Not clearing the cache after changing the loader. Fetching without error handling.

In practice

Use a built-in loader if your content is in files. Write a custom one only for an outside source. Add retries and a clear error for network failures.

See also

Content collections, Astro

Sources

Count this on a real site.

Watch my website