Lazy initialization delays loading or setup until a feature is likely to be needed. It moves noncritical work off the initial render and interaction path; it does not mean delaying everything. section 14.6
Choose what to defer by user-visible priority:
- Load the main document, critical CSS, and core navigation early; defer below-the-fold media and optional features. section 14.6.2
- Use native media attributes or content-visibility for off-screen content, IntersectionObserver for custom viewport logic, and dynamic imports at route, dialog, or widget boundaries. section 14.6 section 14.6.3
- Keep loading, failure, and retry states visible; set image dimensions to prevent layout shifts, and preload only assets users are likely to need soon. section 14.6.2
async function openReportDialog() {
reportButton.disabled = true;
try {
const { showReportDialog } = await import("./report-dialog.js");
await showReportDialog();
} catch (error) {
showToast("The report tools could not be loaded.");
console.error(error);
} finally {
reportButton.disabled = false;
}
}
A report dialog loads when requested; the button is disabled during loading, errors are surfaced, and the button is restored afterward. section 14.6.2











