⚙️ Installation & Configuration
Cdn
📖 Docs

CDN - Content Delivery Network - Optimizely DXP

Exam Area: Area 2 – Installation, Operation & Configuration (20%)


1. CDN in DXP

DXP integrates Azure CDN for static assets and optionally full-page caching.


2. CDN Caching Types

TypeDescription
Static CDNCSS, JS, images from the /Static/ folder
Blob CDNMedia from Azure Blob Storage
Full-page CDNHTML pages (optional, requires setup)

3. Static File Caching Headers

// Program.cs - Configure static file caching
app.UseStaticFiles(new StaticFileOptions
{
    OnPrepareResponse = ctx =>
    {
        ctx.Context.Response.Headers.Add(
            "Cache-Control", 
            "public, max-age=31536000");  // 1 year
    }
});

4. CDN URL for Blob Storage

// Blob media served via a CDN URL
// appsettings.json:
{
  "EPiServer": {
    "CmsAzureBlobStorageProvider": {
      "ConnectionString": "...",
      "ContainerName": "mysitemedia",
      "CdnEndpoint": "https://mysite.azureedge.net"  // CDN endpoint
    }
  }
}

5. Cache Purge on Publish

// Purge CDN cache when content is published
[InitializableModule]
public class CdnCachePurgeModule : IInitializableModule
{
    private IContentEvents _events;

    public void Initialize(InitializationEngine context)
    {
        _events = context.Locate.Advanced.GetInstance<IContentEvents>();
        _events.PublishedContent += OnPublished;
    }

    public void Uninitialize(InitializationEngine context)
    {
        _events.PublishedContent -= OnPublished;
    }

    private async void OnPublished(object sender, ContentEventArgs e)
    {
        // Get page URL
        var urlResolver = ServiceLocator.Current.GetInstance<IUrlResolver>();
        var url = urlResolver.GetUrl(e.ContentLink);
        
        // Purge from CDN
        await CdnService.PurgeAsync(url);
    }
}

6. CDN Configuration in the PaaS Portal

PaaS Portal → Environment → CDN
  → Enable/Disable CDN
  → CDN endpoint URL
  → Purge cache (manual)
  → Cache rules

7. Response Cache Headers

// Controller-level caching
[ResponseCache(Duration = 3600, Location = ResponseCacheLocation.Any)]
public class StaticContentController : PageController<StaticPage>
{
    public ActionResult Index(StaticPage currentPage)
    {
        return View(currentPage);
    }
}

// Disable caching (for personalized content)
[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
public class PersonalizedController : PageController<PersonalizedPage> { }

Review Questions

  1. Which service does CDN use in DXP? (Azure CDN / Azure Front Door)
  2. Can Blob media be served via CDN? (Yes — using the CdnEndpoint configuration)
  3. Why should you purge the CDN cache when publishing? (New content is published but the CDN still has the old cached version)
  4. Should personalized pages be CDN-cached? (No — each user sees different content)
  5. Where is CDN managed in DXP? (PaaS Portal → Environment → CDN)