SSR Transfer State
Note: Spartacus 4.x is no longer maintained. Please upgrade to the latest version.
Note: Spartacus 4.x was tested with SAP Commerce Cloud versions 1905 to 2205. Spartacus 4.x has not been verified to work with (and is not guaranteed to work with) SAP Commerce Cloud 2211 or later releases.
Spartacus runs XHR requests on the server, and then again on the client-side when the application bootstraps. To prevent unnecessary calls to the back end for the state that was already populated on the server, Spartacus includes part of the NgRx state with the server-side rendered HTML.
You can configure the transfer of state for CMS and products (from NgRx store), as shown in the following example:
ConfigModule.withConfig({
state: {
ssrTransfer: {
keys: {
products: true,
cms: true
}
}
}
});
You can also narrow the configuration to specific state sub-parts, as shown in the following example:
ConfigModule.withConfig({
state: {
ssrTransfer: {
keys: {
products: StateTransferType.TRANSFER_STATE,
cms: StateTransferType.TRANSFER_STATE,
},
},
}
});