Production and testing · senior
Bundle size, @defer, server rendering and hydration
Measure the bundle, lazy load what is not needed first, defer parts of templates, and keep server and browser DOM equal for hydration.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Measure:
ng build --stats-jsonwith a bundle analyser, and Lighthouse or WebPageTest on a throttled phone. - Usual causes of a big initial bundle: eagerly imported feature components, barrel files that pull heavy code, a date library with every locale.
@deferloads a block (its components, directives and pipes) only when a trigger fires:on viewport,on interaction,on hover,on idle(default),on timer,when condition. Useprefetchto download earlier.- Deferred dependencies must be standalone, and must not be used outside the block, or they stay in the main bundle.
- Hydration reuses the server DOM. NG0500 means a node did not match. Causes: direct DOM changes (
innerHTML, jQuery), invalid HTML nesting, browser-only code run on the server. - The server waits until the app is stable before sending HTML. An endless
intervalor timer started during rendering makes the request hang. - Start timers only in the browser, for example after render.
The red pen
Common traps: mistake → fix
Mistake: @defer always reduces the bundle
Fix: only if its dependencies are standalone and not used elsewhere eagerly.
Mistake: SSR hydration mismatch is only cosmetic
Fix: it can re-render or break the part.
Easy to hard
Questions interviewers ask, easy to hard
- The bundle is too big. What do you check?
- When does @defer not make a page lighter?
- What causes NG0500?
- The server-rendered home page hangs. Why?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.