Question presented to candidate:
"Lighthouse flags our product pages for a slow Largest Contentful Paint and layout shift from images. How would you use Angular's NgOptimizedImage to fix it, and what does the directive actually do to the <img> tag?"
What a strong answer should cover:
- Import
NgOptimizedImageand replacesrcwithngSrc;width/height(orfill) are required to prevent layout shift. - Defaults:
loading="lazy";prioritymakes the image eager withfetchpriority="high"and adds a preload link during SSR. - Loaders (
provideImgixLoader,provideCloudinaryLoader, ... or a customIMAGE_LOADER) enable automaticsrcset: density descriptors (1x, 2x) or width descriptors withsizes. fillmode for unknown dimensions;placeholderfor low-quality previews.- Dev-mode checks: missing dimensions,
srcwithngSrc, base64 sources, pixelsizes, missing preconnect for priority images, LCP image not marked priority. - It does not resize images itself; the CDN does.
Clarifying questions expected:
- "Which image CDN do we use? That determines the loader."
- "Is the page server-rendered? Preload links only appear with SSR or prerendering."
Code / implementation expected: Yes β a few <img ngSrc> tags covering priority, responsive and fill cases.