Skip to main content

SitecoreAI · Tutorial

Serving Content Hub (DAM) Images Through next/image

Allow Content Hub image hosts in next.config.js and your image wrapper, including the SVG gotcha.

gavAusWeb1 min read

XM Cloud's out-of-the-box config already allows the media library hosts, so you rarely need to touch it. A DAM like Content Hub (or any other) is different: its host has to be added before next/image will serve its images.

Two places to updateLink to this section

1. next.config.jsLink to this section

Add the DAM host to images.remotePatterns:

next.config.jsjs
images: {
  remotePatterns: [
    { protocol: 'https', hostname: 'edge*.**', port: '' },
    { protocol: 'https', hostname: 'xmc-*.**', port: '' },
    { protocol: 'https', hostname: 'xmcloudcm.localhost', port: '' },
    // Content Hub public links
    { protocol: 'https', hostname: '*.sitecorecontenthub.cloud', port: '' },
  ],
  // Content Hub SVG URLs have no .svg extension, so they reach the optimiser.
  // Allow them (served as-is) under Next's recommended sandbox.
  dangerouslyAllowSVG: true,
  contentDispositionType: 'attachment',
  contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
},

2. Your image wrapperLink to this section

If you have a custom image component that decides whether to optimise, it needs the same allow-list:

Image wrapperts
const remotePatterns = ['edge*.**', 'xmc-*.**', '*.localhost', '*.sitecorecontenthub.cloud'];
const toRegex = (pattern: string) => pattern.replace('.', '\\.').replace(/\*/g, '.*');

const shouldOptimize = (src?: string) => {
  if (!src || src.includes('.svg')) return false;
  if (!src.startsWith('http')) return true; // relative path
  const { hostname } = new URL(src);
  return remotePatterns.some((p) => new RegExp(`^${toRegex(p)}$`).test(hostname));
};