Browser & Web Performance Junior cheat sheet: interview answers

Every question of this level with its correct answer and explanation, on one page for a quick review before the interview.

  1. 1. You type a URL and press Enter. Which order of steps is closest to what the browser does first?

    Correct answer: DNS, TCP and TLS, HTTP request, then parsing HTML

    The browser must resolve the host name to an IP, open a connection (plus TLS for HTTPS) and send the request before it gets any HTML to parse.

  2. 2. What does the browser build from the HTML it parses?

    Correct answer: The DOM, a tree of nodes for the document

    HTML is tokenized into nodes that form the DOM. CSS is parsed separately into the CSSOM; both are combined later.

  3. 3. What is the render tree?

    Correct answer: DOM and CSSOM combined, containing only the visible nodes with their computed styles

    Elements with display: none and non-visual nodes like <head> are left out. The render tree is the input to layout.

  4. 4. Which order of rendering stages is correct after the render tree is built?

    Correct answer: Layout, paint, composite

    Layout computes geometry, paint fills in pixels for layers, and compositing draws the layers on screen in the right order.

  5. 5. What happens during the layout (reflow) stage?

    Correct answer: It calculates the size and position of every box

    Layout turns styles into geometry: widths, heights and coordinates. Changing geometry later forces layout to run again.

  6. 6. What is the critical rendering path?

    Correct answer: The steps from receiving HTML to the first pixels

    Optimizing it (fewer render-blocking resources, smaller critical CSS) gets content on screen sooner.

  7. 7. Why is CSS called render-blocking?

    Correct answer: The page won't render until the CSSOM is built

    Painting before styles are known would cause a flash of unstyled content. That's why critical CSS should be small and arrive early.

  8. 8. What does a classic <script src> without async or defer do to HTML parsing?

    Correct answer: Pauses parsing until the script is downloaded and executed

    Such a script is parser-blocking, because it might use document.write or read the DOM built so far.

  9. 9. What's the difference between defer and async on a script?

    Correct answer: defer runs after parsing in document order; async runs as soon as it downloads, in any order

    Both download without blocking the parser. defer suits app code that depends on order and the DOM; async suits independent scripts like analytics.

  10. 10. How does <script type="module"> load by default?

    Correct answer: Like defer: after the document is parsed

    Module scripts are deferred by default. Adding async makes them run as soon as they and their imports are ready.

  11. 11. What's the difference between the DOMContentLoaded and load events?

    Correct answer: load also waits for images and styles

    Code that needs the DOM can start at DOMContentLoaded; load is later and depends on every subresource.

  12. 12. What is the browser's preload scanner?

    Correct answer: A second parser that finds resources ahead of time

    It lets downloads start even while the main parser is blocked. Resources hidden in JS or CSS (e.g. injected images) can't be discovered by it.

  13. 13. Which three metrics are the Core Web Vitals today?

    Correct answer: LCP, INP and CLS

    INP replaced FID as a Core Web Vital in March 2024. TTFB and FCP are useful supporting metrics but not Core Web Vitals.

  14. 14. What does LCP (Largest Contentful Paint) measure?

    Correct answer: When the largest image or text block in the viewport is rendered

    LCP approximates when the main content becomes visible. The time of the first content of any kind is FCP.

  15. 15. What is a 'good' LCP value?

    Correct answer: 2.5 seconds or less

    Good is ≤ 2.5 s, poor is above 4 s, measured at the 75th percentile of page loads.

  16. 16. What does INP (Interaction to Next Paint) measure?

    Correct answer: How quickly the page visually responds to input

    INP looks at all interactions and reports one of the slowest. FID only measured the input delay of the first interaction.

  17. 17. What is a 'good' INP value?

    Correct answer: 200 ms or less

    Good is ≤ 200 ms and poor is above 500 ms. 0.1 is the CLS threshold and 2.5 s is LCP's.

  18. 18. What does CLS (Cumulative Layout Shift) measure?

    Correct answer: How much visible content unexpectedly moves

    CLS is a unitless score; a good value is 0.1 or less. Typical causes are images without dimensions, late ads and font swaps.

  19. 19. Which change is most likely to reduce CLS caused by images?

    Correct answer: Set width and height attributes on images

    With known dimensions the browser reserves space before the image arrives, so nothing jumps when it loads.

  20. 20. What does TTFB (Time to First Byte) measure?

    Correct answer: The time until the first response byte arrives

    TTFB includes redirects, DNS, connection setup and server processing. A slow TTFB delays every later metric, including LCP.

  21. 21. What does FCP (First Contentful Paint) measure?

    Correct answer: When the first text or image is rendered

    FCP tells the user something is happening. LCP is about the main content, which often comes later.

  22. 22. What's the difference between lab data and field data?

    Correct answer: Lab data is a controlled test; field data is real users

    Lab tests are reproducible and good for debugging; field data (RUM, CrUX) shows what users actually experience. They often disagree.

  23. 23. Which tool gives you a lab performance report with suggestions directly in Chrome?

    Correct answer: Lighthouse

    Lighthouse runs a page load in controlled conditions. CrUX is a dataset of field data from real Chrome users.

  24. 24. Why can't Lighthouse report INP in a normal page-load audit?

    Correct answer: INP needs real interactions, which an audit lacks

    Lab tools use Total Blocking Time (TBT) as a proxy: long main-thread tasks during load usually mean poor responsiveness.

  25. 25. What is a long task on the main thread?

    Correct answer: A task that runs for more than 50 ms

    While a long task runs, the browser can't respond to input or render, which hurts INP.

  26. 26. Why does heavy JavaScript make a page feel slow even after it has loaded?

    Correct answer: It runs on the main thread, which also handles input

    Splitting work into smaller tasks, deferring non-critical code and moving heavy computation to workers keeps the main thread free.

  27. 27. What does loading="lazy" on an <img> do?

    Correct answer: Delays loading until it's near the viewport

    Native lazy loading saves bandwidth for offscreen images. It should not be used on the LCP image above the fold.

  28. 28. Why shouldn't you add loading="lazy" to the hero image at the top of the page?

    Correct answer: It's likely the LCP element, so its load is delayed

    The browser waits for layout to know the image is in view before fetching it, which pushes LCP later.

  29. 29. What does srcset with sizes on an <img> let the browser do?

    Correct answer: Pick the best file for the screen and pixel density

    Phones then download a small file instead of the desktop-sized image, which saves bytes and speeds up LCP.

  30. 30. Which image formats usually give smaller files than JPEG and PNG at similar quality?

    Correct answer: AVIF and WebP

    Modern formats compress better. <picture> with <source type> lets you offer them with a fallback.

  31. 31. What does font-display: swap do?

    Correct answer: Shows a fallback font, then swaps to the web font

    Text is readable immediately (no invisible text), at the cost of a possible layout shift when the font swaps.

  32. 32. What is FOIT?

    Correct answer: Hidden text while the web font is still loading

    With the default font-display: auto many browsers hide text for up to about 3 seconds. swap or optional avoid it.

  33. 33. Which is a cheap way to make images download faster without changing their content?

    Correct answer: Serve a modern format at the displayed size

    Oversized images are one of the most common performance problems. Base64 inlining makes HTML bigger and blocks caching.

  34. 34. What does <link rel="preload"> do?

    Correct answer: Fetches a current-page resource early

    Preload is for current-page resources the preload scanner can't find early, like fonts referenced from CSS or a hero image set in CSS.

  35. 35. What does <link rel="preconnect" href="https://cdn.example.com"> do?

    Correct answer: Opens the connection (DNS, TCP, TLS) to that origin in advance

    When the first request to that origin happens, the connection is ready, saving one or more round trips.

  36. 36. What is <link rel="prefetch"> meant for?

    Correct answer: Low-priority fetching for a future navigation

    Prefetched resources go into the HTTP cache and are used if the user navigates there. For the current page use preload.

  37. 37. What does dns-prefetch do?

    Correct answer: Resolves the domain name in advance

    It's the lightest hint: only DNS. preconnect goes further and also sets up TCP and TLS.

  38. 38. What does Cache-Control: max-age=3600 mean?

    Correct answer: It can be reused without asking for 3600 seconds

    During that hour the response is fresh. After it expires the cache must revalidate or refetch it.

  39. 39. What's the difference between no-cache and no-store?

    Correct answer: no-cache revalidates; no-store forbids storing

    The names are confusing. no-cache still saves bandwidth through 304 Not Modified; no-store is for sensitive data that must not be kept.

  40. 40. What is an ETag used for?

    Correct answer: Identifying a resource version for revalidation

    If the resource hasn't changed, the server answers 304 Not Modified with no body, and the cached copy is reused.

  41. 41. What does a 304 Not Modified response mean?

    Correct answer: The cached copy is still valid; no body is sent

    It's the answer to a conditional request (If-None-Match or If-Modified-Since). It saves bytes but still costs a round trip.

  42. 42. Why do build tools put a content hash in file names like app.3f9a1c.js?

    Correct answer: So the file can be cached for a very long time

    Hashed assets can use Cache-Control: max-age=31536000, immutable. The HTML that references them is cached briefly or revalidated.

  43. 43. Which caching policy fits the HTML page of a frequently updated site that uses hashed asset URLs?

    Correct answer: no-cache or a short max-age

    If the HTML is cached for a year, users keep loading old asset URLs. Without any header browsers may cache it heuristically.

  44. 44. What does Cache-Control: private mean?

    Correct answer: Only the user's browser may cache the response

    Use it for personalized responses. public allows shared caches; no-store forbids caching completely.

  45. 45. Where can an HTTP response be cached on its way to the user?

    Correct answer: In the browser cache and in shared caches

    Shared caches serve many users, which is why private and s-maxage exist to control them separately.

  46. 46. What does a hard reload (Ctrl+Shift+R) typically do with the cache?

    Correct answer: Requests resources again, bypassing the cache

    It's handy for checking a deploy, but real users rarely do it, so caching headers must be correct.

  47. 47. Why does serving text resources with Brotli or gzip help performance?

    Correct answer: It makes HTML, CSS and JS smaller to transfer

    Text compresses very well. The browser advertises support in Accept-Encoding, the server answers with Content-Encoding.

  48. 48. What is a key benefit of HTTP/2 over HTTP/1.1?

    Correct answer: Many requests are multiplexed over a single connection

    With HTTP/1.1 browsers opened several connections per host and hacks like sprites and domain sharding were common.

  49. 49. How does a CDN make a site faster?

    Correct answer: It serves cached content from servers close to users

    Shorter distance means lower latency; the CDN also offloads traffic from the origin.

  50. 50. Why are redirects bad for page load speed?

    Correct answer: Each one adds an extra round trip

    For example http://site.com → https://site.com → https://www.site.com adds two round trips to TTFB.

  51. 51. What makes two URLs the same origin?

    Correct answer: Same scheme, host and port

    https://a.com and http://a.com differ in scheme; https://a.com and https://api.a.com differ in host.

  52. 52. Are https://example.com and https://example.com:8443 the same origin?

    Correct answer: No, the port is different

    The port is part of the origin. The default HTTPS port is 443.

  53. 53. What does the same-origin policy prevent by default?

    Correct answer: Reading another origin's responses or DOM

    Embedding cross-origin images, scripts and form submissions is allowed; reading the data back from script is not.

  54. 54. What is CORS?

    Correct answer: A way for a server to allow other origins to read

    CORS relaxes the same-origin policy in a controlled way, using response headers like Access-Control-Allow-Origin.

  55. 55. Who enforces CORS?

    Correct answer: The browser

    The server only sends headers; the browser decides whether page script may read the response. curl or a backend ignore CORS entirely.

  56. 56. A frontend on https://app.com calls https://api.com and sees a CORS error. Where is the fix usually needed?

    Correct answer: On api.com: it must return the right Access-Control-Allow-* headers

    no-cors gives an opaque response that script can't read. The API (or a proxy in front of it) must allow the origin.

  57. 57. What is a CORS preflight request?

    Correct answer: An OPTIONS request asking whether a call is allowed

    It's sent for non-simple requests, for example with PUT, DELETE, a JSON Content-Type or custom headers.

  58. 58. Which header in a response allows any origin to read it?

    Correct answer: Access-Control-Allow-Origin: *

    * is fine for public data. It can't be combined with credentialed requests; then the exact origin must be echoed.

  59. 59. What is cross-site scripting (XSS)?

    Correct answer: An attacker's script runs in the context of your origin

    The injected script can read data on the page, act as the user and steal tokens available to JavaScript.

  60. 60. Which way of putting user input into the page is safe from XSS?

    Correct answer: el.textContent = userInput

    textContent treats the value as text, so <script> or <img onerror> are just characters, not markup.

  61. 61. Why don't React and Vue templates usually cause XSS when you render {userInput}?

    Correct answer: They escape values inserted as text by default

    Escaping is the default; risk returns with escape hatches like dangerouslySetInnerHTML or v-html, and with javascript: URLs.

  62. 62. What are the three classic types of XSS?

    Correct answer: Stored, reflected and DOM-based

    Stored XSS is saved on the server, reflected comes back in the response to a crafted request, DOM-based happens entirely in client-side JS.

  63. 63. What is Content Security Policy (CSP)?

    Correct answer: A header listing allowed content sources

    CSP is a second line of defense: even if markup is injected, scripts not allowed by the policy won't run.

  64. 64. If you must insert user-provided HTML (e.g. formatted comments), what should you do?

    Correct answer: Sanitize it with a library like DOMPurify

    Regex filters miss vectors like <img src=x onerror=...> or <svg onload>. A real sanitizer parses HTML and keeps only an allowlist.

  65. 65. What does the HttpOnly flag on a cookie do?

    Correct answer: Hides the cookie from JavaScript

    An XSS payload then can't read a session cookie directly, which limits the damage.

  66. 66. What does the Secure flag on a cookie do?

    Correct answer: The cookie is sent only over HTTPS

    It stops the cookie from leaking over plain HTTP. SameSite=None cookies must also be Secure.

  67. 67. What does SameSite=Lax mean for a cookie?

    Correct answer: Sent on top-level navigations, not most cross-site calls

    Lax protects against many CSRF attacks while keeping links from other sites working. Chrome treats cookies without SameSite as Lax.

  68. 68. Why is storing an auth token in localStorage considered risky?

    Correct answer: Any script running on the page, including injected XSS, can read it

    localStorage has no HttpOnly equivalent. An HttpOnly, Secure, SameSite cookie keeps the token out of reach of JS.

  69. 69. How do cookies affect performance?

    Correct answer: They are sent with every request to their domain

    Large cookies inflate every request, including requests for images and scripts on the same domain.

  70. 70. What is mixed content?

    Correct answer: An HTTPS page loading some resources over plain HTTP

    Browsers block mixed scripts and other active content, and upgrade or block images and media. Everything should be served over HTTPS.

  71. 71. What does the Strict-Transport-Security (HSTS) header do?

    Correct answer: Tells the browser to use only HTTPS for this site

    After the first visit the browser upgrades http:// links itself, which prevents SSL-stripping on later visits.

  72. 72. Why is HTTPS required for many modern web features like service workers?

    Correct answer: Attackers on the network could otherwise inject code

    A service worker can intercept every request of a site; letting a network attacker install one would be disastrous.

  73. 73. What does Content-Encoding: br in a response mean?

    Correct answer: The body is compressed with Brotli

    The browser decompresses it transparently. The server chooses the encoding based on the Accept-Encoding request header.

  74. 74. What does <img decoding="async"> hint to the browser?

    Correct answer: Decoding may happen without delaying other content

    It's a small hint; the main wins for images still come from size, format and correct priority.

  75. 75. Which DevTools panel shows each request's timing, size, status and caching?

    Correct answer: Network

    The Network panel shows whether a response came from memory cache, disk cache or service worker, plus a waterfall of timing phases.