Personalize content with CDN caching
When using Magnolia’s personalization features (traits and variants) with CDN caching enabled, special configuration is required to ensure cached content respects user traits.
The problem
Magnolia DX Core allows you to create content variants that display different content based on user traits. However, when CDN caching is enabled:
- Without caching: Users see personalized content correctly based on their traits.
- With caching: All users see the same cached version (the first response the CDN cached), regardless of their traits.
This happens because CDNs treat all requests to the same URL as identical. The CDN caches the first response and serves it to everyone, ignoring trait differences.
The solution
Personalized content can be cached correctly by configuring the CDN to:
- Extract trait information from incoming requests
- Normalize trait values into a small set of categories
- Create separate cache entries for each trait category using the
Varyheader
Implementation approach
The configuration works in three stages of the CDN request lifecycle:
- Request received: Extract trait data (such as device type from User-Agent headers) and normalize it into categories
- Backend response received: Configure the
Varyheader to create separate cache entries for each trait category - Response delivered: Clean up internal headers before sending the response to the client
Common personalization traits that work well with this approach include:
- Device type (mobile, tablet, desktop)
- Geographic region (continent or country-level)
- User segments with limited categories
Getting personalization with caching configured
CDN configuration for personalized content caching is managed by Magnolia Support for DX Cloud projects.
To request this configuration:
- Contact DX Cloud support.
- Provide details about your personalization requirements:
- Which traits you want to use (device type, location, etc.)
- Expected trait values and categories
- Which pages or content types require personalization
- Support will work with you to implement the appropriate CDN configuration.
Related topics
- For Magnolia personalization concepts and configuration, see the Personalization module
- Fastly: VCL best practices