TransferStateService
TheTransferStateService allows you to transfer data from Scully’s static rendering process into the Angular application, eliminating redundant HTTP requests and providing instant content on page load.
Overview
This service works by:- Capturing API responses during Scully’s build process
- Serializing and embedding them in the static HTML
- Rehydrating the data when the Angular app loads
- Providing cached data to components instead of making new API calls
- Faster initial page loads
- Reduced API calls
- Better user experience
- Lower server costs
Installation
The service is automatically provided when you importScullyLibModule with transfer state enabled:
Methods
useScullyTransferState()
name: Unique identifier for this stateoriginalState: Your original observable (e.g., HTTP request)
- During Scully build: Executes
originalState, stores result in state - On first client load: Returns cached state from HTML
- On subsequent navigations: Returns cached state from prefetched data
- On non-Scully pages: Executes
originalStateand stores result
getState()
name: The state key to retrieve
setState()
name: The state keyval: The value to store
stateHasKey()
stateKeyHasValue()
Common Use Cases
Blog Post with API Data
Multiple API Calls
With Loading States
Service Integration
Configuration
Enable Transfer State
Scully Configuration
Configure how state is stored:-
Inline in HTML (
inlineStateOnly: true):- State embedded in the HTML file
- Faster initial load
- Larger HTML files
-
Separate data.json (
inlineStateOnly: false):- State in separate
data.jsonfile - Smaller HTML files
- Requires additional HTTP request
- State in separate
How State is Stored
During the Scully build, state is embedded in the HTML:Advanced Usage
Custom State Management
Handling Errors
Troubleshooting
State Not Being Cached
Ensure transfer state is enabled:State Not Loading
Check that you’re usinguseScullyTransferState() correctly:
State Too Large
Reduce state size by:- Only storing essential data
- Using pagination
- Splitting into multiple state keys

