Edge Delivery Services how-tos · updated
What is auto blocking in AEM Edge Delivery Services, and how do you use it?
Auto blocking creates blocks in code from ordinary content or page metadata, so authors don't have to insert a block table themselves. It runs early in page decoration, in buildAutoBlocks() in your project's scripts.js, and builds the same DOM a block would have if the author had created it.
Why it exists
Tables make documents harder to read and edit, so aem.live recommends leaving as much as possible as default content (headings, text, images, links). Auto blocking keeps that authoring simplicity while letting developers keep layout and behaviour in a block.
Typical uses
- An article header built from the h1, the first image and author and date metadata, for pages whose template metadata says 'article'.
- An embed block wrapped around a YouTube link an author pasted on its own line.
- Links to fragments, modals or forms turned into the matching block.
Auto blocking is often driven by the template metadata property: if every page with template 'blog-post' needs the same header, add it in code rather than asking every author to insert it.
What to watch
Because auto blocking runs before blocks load, keep it cheap: a few DOM queries, no network requests. If the auto block contains the hero image, remember it affects which element becomes the LCP candidate.
Illustrative buildAutoBlocks() adding an embed block around YouTube links
function buildAutoBlocks(main) {
main.querySelectorAll('a[href*="youtube.com"]').forEach((a) => {
if (a.closest('.block')) return;
const block = buildBlock('embed', [[a.cloneNode(true)]]);
a.closest('p')?.replaceWith(block);
});
}How to do it
- List content patterns authors already write naturally (a lone video link, an article h1 + image).
- Decide which block each pattern should become.
- Add the logic to buildAutoBlocks() in scripts.js, using the boilerplate's block-building helper.
- Gate template-wide auto blocks on the template metadata value.
- Preview pages and confirm the generated block matches what an authored block produces.
Related pages on this site
Questions
Where does auto blocking code live?
In buildAutoBlocks() in your project's scripts.js, according to aem.live.
Does auto blocking slow the page?
It runs in the eager phase before LCP, so keep it to simple DOM work with no network calls.
Can authors still add the block manually?
Yes. Make sure your auto-blocking code skips content that is already inside a block.
Sources
- aem.live: Markup, Sections, Blocks, and Auto Blocking (checked 10 Nov 2026)
- aem.live: Web Performance, Keeping your Lighthouse Score 100 (checked 10 Nov 2026)
Facts about Adobe's platform are from the linked Adobe pages, checked 10 Nov 2026. Explanations and examples are ours unless marked as Adobe's.