- Concepts
Loaders
Loaders are the central engine of the Content SDK Angular implementation and the primary enabler of server-side data fetching from SitecoreAI. They function as server-side data resolvers, conceptually similar to Next.js's getServerSideProps or server functions in React Server Components.
The loader flow is built on Angular route data resolvers, but instead of defining separate functions for each resolver, loaders execute through the Content SDK wrapper loaderResolver. Out of the box, loaders populate the page and dictionary properties for a route. You can expand this logic to populate additional route properties when a request is processed by Angular SSR.
Basic usage
You can define loaders on Angular routes by name:
loaderResolver is the main entry point for loader logic and enforces the core design goal of strict server-side data fetching.
Flow of execution
On the server, the execution flow is as follows:
loaderResolverretrieves the loader from the injectable loader registry by name.- It executes the loader or retrieves cached data from
loaderCachedepending on route, language, loader name, and other parameters. - It writes the loader result to Angular's
TRANSFER_STATE, making the value available during client-side navigation without re-executing the loader.
In the browser, the execution flow is as follows:
loaderResolverattempts to read the loader result fromTRANSFER_STATE.- If absent, it invokes a request to the loader-data-service Express.js middleware via
loader-data.service. - The Express middleware retrieves the loader from the registry, executes it (or reads data from the
loaderCache), and responds with the result.
Depending on the loader execution result type (data, error, or notFound), either the specified route property is populated, or loaderResolver invokes a redirect to the appropriate error or not-found page.
Loader registry
Loaders are retrieved from a loader registry injected in src/app.config.ts:
Loader implementations are located in the src/content-sdk/loaders folder.
Loader implementation
The following example shows the default page loader implementation:
Loaders must implement the LoaderFn contract. Loaders can execute outside of the Angular injection context and must not contain any inject() calls.
Caching
The loader execution layer includes a caching mechanism to preserve loader result data. For configuration details, refer to Loader cache layer and tags revalidation.
Link prefetching
Loaders normally fetch data on demand when a route resolver runs. Sitecore link fields rendered through scRouterLink and scRichText can prefetch a destination route's loader data before the user navigates there, so the resolver consumes a staged response instead of starting a fresh request. See Link prefetching for configuration options.
Middleware considerations
Personalize, multisite, and SXA redirect support is implemented through Express.js middleware handlers in the Angular Content SDK.
Because the Angular Content SDK uses a loaders-centric architecture, middleware handlers are invoked on regular server requests and browser navigation requests that resolve loader data for the client side. For a full list of the available middleware plugins and their configuration options, see Middleware plugins.