AEM Edge Delivery Services + AI
AEM Edge Delivery Services + AI: The Future of Content Delivery
Introduction
AEM Edge Delivery Services (EDS) — formerly known as Project Franklin / Helix — is Adobe's modern, high-performance content delivery layer. It decouples content authoring from delivery, serving pages at the edge with near-perfect Lighthouse scores. When you combine EDS with AI, you unlock capabilities like real-time content personalization, AI-generated blocks, and intelligent A/B testing — all at the edge.
In this post, we'll walk through how to integrate AI into an EDS project with practical code examples.
How Edge Delivery Services Works (Quick Recap)
Author (Google Docs / SharePoint / AEM)
↓
AEM Pipeline (Franklin Bot)
↓
Content stored at Edge (Fastly CDN)
↓
User Request → Edge Worker → HTML served in <100ms
EDS pages are built with plain HTML/CSS/JS blocks. There's no traditional AEM dispatcher — content is served directly from the CDN edge.
1. AI-Powered Block Generation at the Edge
You can intercept page requests at the edge and inject AI-generated content into EDS blocks using Cloudflare Workers or Fastly Compute.
Example: AI Summary Block (Cloudflare Worker)
This worker fetches an EDS page, extracts the main content, summarizes it with an AI API, and injects the summary into the page response.
// cloudflare-worker/ai-summary.js
export default {
async fetch(request, env) {
const url = new URL(request.url);
// Fetch the original EDS page
const originalResponse = await fetch(request);
let html = await originalResponse.text();
// Only process article pages
if (!url.pathname.startsWith('/articles/')) {
return new Response(html, originalResponse);
}
// Extract text content (simplified)
const bodyMatch = html.match(/<main[^>]*>([\s\S]*?)<\/main>/i);
const bodyText = bodyMatch
? bodyMatch[1].replace(/<[^>]+>/g, ' ').trim().slice(0, 1500)
: '';
// Call AI API to summarize
const summary = await generateSummary(bodyText, env.OPENAI_API_KEY);
// Inject AI summary block before </main>
const summaryBlock = `
<div class="ai-summary block" data-block-name="ai-summary">
<div>
<div><strong>AI Summary</strong></div>
<div>${summary}</div>
</div>
</div>`;
html = html.replace('</main>', summaryBlock + '</main>');
return new Response(html, {
headers: {
'Content-Type': 'text/html',
'Cache-Control': 'public, max-age=3600',
'X-AI-Enhanced': 'true'
}
});
}
};
async function generateSummary(text, apiKey) {
const response = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-4o-mini',
messages: [
{ role: 'system', content: 'Summarize the following content in 2-3 sentences.' },
{ role: 'user', content: text }
],
max_tokens: 150
})
});
const data = await response.json();
return data.choices?.[0]?.message?.content || '';
}
EDS Block CSS for the AI Summary
/* blocks/ai-summary/ai-summary.css */
.ai-summary {
background: linear-gradient(135deg, #f0f4ff, #e8f0fe);
border-left: 4px solid #4285f4;
border-radius: 8px;
padding: 1.5rem;
margin: 2rem 0;
font-size: 0.95rem;
color: #333;
}
.ai-summary strong {
display: block;
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.1em;
color: #4285f4;
margin-bottom: 0.5rem;
}
2. AI Personalization at the Edge
Instead of personalizing in the browser (slow) or in AEM (coupled), you can personalize content at the edge based on user attributes from a cookie or request header.
Cloudflare Worker — Personalized Hero Block
// cloudflare-worker/personalize.js
export default {
async fetch(request, env) {
const url = new URL(request.url);
const segment = getUserSegment(request); // 'developer' | 'marketer' | 'executive'
const originalResponse = await fetch(request);
let html = await originalResponse.text();
// Generate personalized headline with AI
if (url.pathname === '/' && segment) {
const headline = await personalizeHeadline(segment, env.OPENAI_API_KEY);
// Replace default H1 with personalized one
html = html.replace(
/<h1[^>]*>.*?<\/h1>/i,
`<h1 data-personalized="${segment}">${headline}</h1>`
);
}
return new Response(html, {
headers: { 'Content-Type': 'text/html' }
});
}
};
function getUserSegment(request) {
const cookie = request.headers.get('Cookie') || '';
const match = cookie.match(/user_segment=([^;]+)/);
return match ? match[1] : 'default';
}
async function personalizeHeadline(segment, apiKey) {
const prompts = {
developer: 'Write a headline for AEM targeting software developers. Max 10 words.',
marketer: 'Write a headline for AEM targeting digital marketers. Max 10 words.',
executive: 'Write a headline for AEM targeting C-level executives. Max 10 words.'
};
const response = await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: prompts[segment] }],
max_tokens: 30
})
});
const data = await response.json();
return data.choices?.[0]?.message?.content?.trim() || 'Experience the Future of Content';
}
3. AI-Assisted Authoring in EDS (Google Docs Sidebar)
EDS authors work in Google Docs. You can build a Google Apps Script sidebar that lets authors generate content with AI without leaving their doc.
// Google Apps Script — Code.gs
function onOpen() {
DocumentApp.getUi()
.createMenu('✨ AI Assistant')
.addItem('Generate Content', 'showSidebar')
.addToUi();
}
function showSidebar() {
const html = HtmlService.createHtmlOutputFromFile('Sidebar')
.setTitle('AI Content Assistant');
DocumentApp.getUi().showSidebar(html);
}
function generateAndInsert(prompt) {
const apiKey = PropertiesService.getScriptProperties()
.getProperty('OPENAI_API_KEY');
const payload = {
model: 'gpt-4o',
messages: [
{ role: 'system', content: 'You are an AEM content expert. Write in EDS block-friendly HTML.' },
{ role: 'user', content: prompt }
],
max_tokens: 500
};
const options = {
method: 'post',
contentType: 'application/json',
headers: { Authorization: `Bearer ${apiKey}` },
payload: JSON.stringify(payload)
};
const response = UrlFetchApp.fetch(
'https://api.openai.com/v1/chat/completions', options);
const data = JSON.parse(response.getContentText());
const content = data.choices[0].message.content;
// Insert generated content at cursor position
const doc = DocumentApp.getActiveDocument();
const cursor = doc.getCursor();
if (cursor) {
cursor.insertText(content);
}
return content;
}
<!-- Sidebar.html -->
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; padding: 10px; }
textarea { width: 100%; height: 100px; margin-bottom: 8px; }
button { background: #4285f4; color: white; border: none;
padding: 8px 16px; border-radius: 4px; cursor: pointer; }
</style>
</head>
<body>
<h3>✨ AI Content Assistant</h3>
<textarea id="prompt" placeholder="e.g. Write an intro about AEM Edge Delivery Services..."></textarea>
<button onclick="generate()">Generate</button>
<div id="status"></div>
<script>
function generate() {
const prompt = document.getElementById('prompt').value;
document.getElementById('status').textContent = 'Generating...';
google.script.run
.withSuccessHandler(() => {
document.getElementById('status').textContent = '✅ Inserted into doc!';
})
.generateAndInsert(prompt);
}
</script>
</body>
</html>
4. Caching AI Responses at the Edge
AI API calls are expensive and slow. Cache responses at the edge using the Cache API in Cloudflare Workers:
async function getCachedOrFetchAI(cacheKey, prompt, apiKey) {
const cache = caches.default;
const cachedResponse = await cache.match(cacheKey);
if (cachedResponse) {
return await cachedResponse.text();
}
const aiContent = await callAIAPI(prompt, apiKey);
// Cache for 1 hour
const response = new Response(aiContent, {
headers: { 'Cache-Control': 'public, max-age=3600' }
});
await cache.put(cacheKey, response.clone());
return aiContent;
}
Key Takeaways
- EDS + AI is most powerful when AI runs at the edge, not in the browser — reducing latency and protecting API keys.
- Cache AI responses aggressively — same prompt = same response, so caching is safe and dramatically reduces cost.
- Use Google Apps Script sidebars to bring AI to EDS authors without changing their authoring workflow.
- Always add a data attribute (
data-ai-enhanced,data-personalized) to AI-modified blocks for debugging and analytics.
Comments
Post a Comment