What happens between typing a URL in the browser and seeing the page rendered? Focus on the frontend side.
What the interviewer wants to hear
- DNS lookup, TCP/TLS connection and the HTTP request for the HTML
- The browser parses HTML into the DOM and CSS into the CSSOM
- Scripts can block parsing unless they use defer, async or type module
- DOM and CSSOM combine into the render tree, followed by layout, paint and compositing
- Optimise the critical rendering path: less render-blocking CSS and JS, preload key resources
Model answer
The browser resolves the domain with DNS, opens a connection with TLS, and sends an HTTP request; caches and a CDN can shorten this. As the HTML streams in, the parser builds the DOM and the preload scanner starts fetching CSS, scripts and images it finds. CSS is parsed into the CSSOM and is render-blocking, because the browser will not paint without styles. A classic script without defer or async pauses parsing while it downloads and runs. Once DOM and CSSOM are ready, the browser builds the render tree, calculates layout, which is the size and position of every box, then paints pixels into layers and composites them on the GPU. Later changes from JavaScript can trigger layout or paint again. To speed this up I reduce render-blocking resources, inline critical CSS, defer scripts, preload the LCP image and fonts, and keep the HTML small so the first paint happens early.
Can you answer it under time pressure?
Take a timed medium round and get scored on every answer.
More medium Frontend Developer questions
- Explain the JavaScript event loop, including microtasks and macrotasks.
- How do you decide where to keep state in a React app: local state, context, a store, or a server-cache library?
- A page has a poor LCP score. How would you investigate and fix it?
- What testing strategy would you use for a frontend application?
- Explain client-side rendering, server-side rendering and static site generation. When would you use each?
- A React screen feels slow. How do you find and reduce unnecessary re-renders?
- How do you handle loading, error and empty states when a screen fetches data from an API?
- How do you use TypeScript effectively in a React codebase?
- How would you handle user authentication and tokens in a single-page app or Next.js frontend?