🌍 Front-end Web Development · subject

Front-end Web Development Performance Optimization Syllabus

The Performance Optimization syllabus for Front-end Web Development in full: 2 chapters and 4 topics, every one listed below, plus 50 Performance Optimization flashcards with answers.

2Chapters
4Topics
50Flashcards

Performance Optimization syllabus: all 2 chapters

Expand any chapter to see its topics and sub-topics.

  1. Loading Optimization

    2 topics
    • Lazy Loading
    • Code Splitting
  2. Rendering Optimization

    2 topics
    • Virtual DOM
    • Reconciliation

Front-end Web Development Performance Optimization flashcards — 50 questions with answers

  1. What is lazy loading in front-end web development?

    Lazy loading is a performance optimization technique that defers the loading of non-critical resources (images, components, modules, scripts) until they are actually needed, rather than loading everything during the initial page load.

  2. What is the primary performance benefit of lazy loading?

    It reduces the initial bundle size and initial load time, lowering Time to Interactive (TTI) and saving bandwidth, since resources are fetched on demand instead of all at once.

  3. Which native HTML attribute enables lazy loading of images and iframes?

    The loading="lazy" attribute (e.g., <img src="..." loading="lazy">). Its other values are loading="eager" (load immediately) and loading="auto" (browser decides).

  4. Which browser API is commonly used to implement custom lazy loading by detecting when an element enters the viewport?

    The Intersection Observer API, which asynchronously observes intersection of a target element with the viewport (or an ancestor), avoiding expensive scroll-event listeners.

  5. In React, which function and component are used to lazy load a component?

    React.lazy() to dynamically import the component, wrapped in a <Suspense fallback={...}> boundary that shows a fallback (e.g., a spinner) while the component loads.

  6. What JavaScript syntax triggers a dynamic import used for lazy loading modules?

    The dynamic import() expression, e.g., import('./module.js'), which returns a Promise that resolves to the module and creates a separate chunk.

  7. What is 'above the fold' content and how does it relate to lazy loading?

    Above-the-fold content is what is visible in the viewport without scrolling. It should be loaded eagerly, while below-the-fold content is a prime candidate for lazy loading.

  8. What is a potential downside of lazy loading content that affects user experience?

    It can introduce a loading delay or layout shift when content appears, and if not handled (e.g., with placeholders/skeletons or reserved space), it can hurt perceived performance and Cumulative Layout Shift (CLS).

  9. What is code splitting?

    Code splitting is the practice of breaking a large JavaScript bundle into smaller chunks that can be loaded on demand or in parallel, so users only download the code they need for the current view.

  10. What is the main difference between lazy loading and code splitting?

    Code splitting is the build-time technique of dividing code into separate chunks; lazy loading is the runtime strategy of deferring when those chunks (or other resources) are actually fetched. They are often used together.

  11. Name two common strategies for code splitting in a single-page application.

    Route-based splitting (a chunk per route/page) and component-based splitting (splitting heavy or rarely-used components). Vendor splitting (separating third-party libraries) is another common strategy.

  12. In Webpack, what does 'tree shaking' do and how does it complement code splitting?

    Tree shaking removes unused (dead) code from the bundle by relying on ES module static analysis. Combined with code splitting, it ensures each chunk contains only the code that is actually reachable and used.

  13. What is a 'vendor chunk' in code splitting?

    A vendor chunk is a separate bundle containing third-party library code (e.g., React, lodash) that changes infrequently, allowing it to be cached long-term by the browser independently of frequently-changing app code.

  14. How does code splitting improve caching efficiency?

    By isolating rarely-changing code (e.g., vendor libraries) into separate chunks with content-hashed filenames, only the chunks that actually change need to be re-downloaded, so unchanged chunks stay in the browser cache.

  15. What is route-based code splitting?

    A strategy where the application is split so each route/page loads its own chunk only when the user navigates to it, keeping the initial load small.

  16. What is the Virtual DOM?

    The Virtual DOM is an in-memory, lightweight JavaScript representation (a tree of plain objects) of the real DOM. The UI library keeps this virtual tree in sync with the actual DOM, computing minimal updates to apply.

  17. Why is updating the Virtual DOM faster than directly updating the real DOM?

    Manipulating plain JavaScript objects is cheaper than manipulating real DOM nodes, which trigger layout reflows and repaints. The Virtual DOM batches and minimizes the costly real-DOM operations.

  18. What are the three main steps of a Virtual DOM update cycle?

    1) Render a new virtual tree from updated state, 2) Diff the new virtual tree against the previous one to find changes, 3) Patch (commit) only the changed parts to the real DOM.

  19. What is reconciliation in the context of the Virtual DOM?

    Reconciliation is the process by which a library (e.g., React) compares (diffs) the new Virtual DOM tree with the previous one and determines the minimal set of real-DOM mutations needed to bring the UI up to date.

  20. What is the naive time complexity of comparing two arbitrary trees, and why does React avoid it?

    A general tree-diff algorithm is $O(n^{3})$ for $n$ nodes, which is too expensive for UI. React uses a heuristic diffing algorithm that runs in $O(n)$ by making simplifying assumptions.

Show the other 30 Performance Optimization flashcards
  1. What two key heuristic assumptions does React's reconciliation algorithm make to achieve $O(n)$ diffing?

    1) Two elements of different types produce different trees (so the old subtree is torn down and rebuilt), and 2) Developers can hint stable identity of children across renders using a key prop.

  2. What happens during reconciliation when an element changes its type (e.g., <div> becomes <span>)?

    React tears down the entire old subtree (unmounting components and destroying their state) and builds the new subtree from scratch, rather than trying to match the children.

  3. What is the purpose of the 'key' prop when rendering lists in React?

    The key gives each list item a stable identity across renders so reconciliation can match elements, reuse/move existing DOM nodes and component state, and avoid unnecessary re-creation or mis-association of items.

  4. Why is using an array index as a list 'key' often discouraged?

    When the list is reordered, filtered, or items are inserted/removed, index-based keys no longer map to stable items, causing React to mis-match elements, leading to incorrect state retention and unnecessary DOM updates.

  5. What is the difference between the 'render phase' and the 'commit phase' in React reconciliation?

    The render phase builds the new virtual tree and diffs it (can be paused/aborted and is side-effect-free); the commit phase applies the computed changes to the real DOM and runs effects (must run synchronously to completion).

  6. What is React Fiber?

    React Fiber is the reconciliation engine (introduced in React 16) that re-implements the algorithm to support incremental rendering: work can be split into units, paused, prioritized, and resumed, enabling features like concurrent rendering.

  7. What does 'diffing' produce as its output in a Virtual DOM library?

    Diffing produces a set of minimal changes (a patch/effect list) describing which nodes to add, remove, move, or update, which is then applied to the real DOM in the commit step.

  8. What is the difference between eager loading and lazy loading?

    Eager loading fetches resources upfront during the initial load (good for critical content), while lazy loading defers fetching until the resource is needed (good for non-critical/off-screen content).

  9. What is 'prefetching' and how does it relate to lazy loading and code splitting?

    Prefetching loads a likely-needed chunk or resource during browser idle time (e.g., via <link rel="prefetch">) so that when the user navigates, the lazily-split chunk is already cached, eliminating the on-demand load delay.

  10. What is the difference between <link rel="preload"> and <link rel="prefetch">?

    preload fetches a resource needed for the current page with high priority (fetched early); prefetch fetches a resource likely needed for a future navigation at low priority during idle time.

  11. What is a 'chunk' in the context of code splitting?

    A chunk is one of the separate output bundles produced when a bundler splits the codebase; each chunk can be loaded independently, on demand or in parallel.

  12. How does a Suspense boundary handle multiple lazy components loading at once?

    A single <Suspense> boundary waits for all lazy components inside it to load before revealing its content, showing the fallback meanwhile. Nesting boundaries allows independent/granular loading states.

  13. What metric measures how long until a page becomes fully interactive, often improved by lazy loading and code splitting?

    Time to Interactive (TTI) — the time until the page is reliably responsive to user input. Reducing initial JavaScript via splitting and lazy loading lowers TTI.

  14. What is 'render-blocking' JavaScript and how does code splitting help?

    Render-blocking JavaScript is script that must be downloaded, parsed, and executed before the page can render or become interactive. Code splitting reduces the amount loaded upfront, shrinking the render-blocking payload.

  15. In Virtual DOM diffing, what happens to children that have the same key but a new position in the list?

    React reuses the existing DOM node and component instance (preserving its state) and simply moves it to the new position, instead of destroying and recreating it.

  16. What is 'batching' of updates in a Virtual DOM library?

    Batching groups multiple state updates within the same event/cycle into a single re-render and a single reconciliation pass, avoiding redundant intermediate DOM mutations and improving performance.

  17. What is the relationship between the Virtual DOM and reconciliation?

    The Virtual DOM is the data structure (the in-memory tree); reconciliation is the algorithm/process that diffs successive Virtual DOM trees and reconciles the real DOM to match the latest one.

  18. Does using a Virtual DOM make an application universally faster than direct DOM manipulation?

    No. The Virtual DOM adds overhead (building and diffing trees). Hand-optimized direct DOM updates can be faster; the Virtual DOM's value is predictable, declarative updates with good-enough performance at scale, not absolute peak speed.

  19. What is component-level (component-based) code splitting?

    Splitting at the level of individual components so that a heavy or infrequently-used component (e.g., a modal, chart, or editor) loads its own chunk only when it is rendered.

  20. What is the purpose of a 'skeleton screen' or placeholder when lazy loading content?

    It reserves space and provides visual feedback while deferred content loads, improving perceived performance and preventing layout shift (reducing CLS).

  21. Which Core Web Vital can be negatively affected by poorly implemented lazy loading, and why?

    Cumulative Layout Shift (CLS), because content that loads in without reserved dimensions pushes other elements around, causing visible layout jumps. Largest Contentful Paint (LCP) can also worsen if the LCP image is lazy-loaded.

  22. What is the difference between static and dynamic imports in JavaScript?

    A static import (import x from 'y') is resolved at build/parse time and always included in the bundle; a dynamic import() is evaluated at runtime, returns a Promise, and enables on-demand code splitting.

  23. In reconciliation, what does it mean that the diffing algorithm compares trees 'level by level' (breadth/level comparison)?

    React compares nodes at the same position/level of the two trees rather than searching across levels. Moving a subtree to a different depth is treated as removing it and creating it anew, keeping the diff linear.

  24. What is the benefit of code splitting for a returning user with a warm cache?

    Unchanged chunks (especially vendor chunks with stable content hashes) are served from cache, so the returning user downloads only the chunks that changed, dramatically reducing repeat-visit load time.

  25. How do lazy loading and code splitting work together in a typical SPA route?

    The build tool code-splits each route into its own chunk, and the router lazy loads that chunk only when the user navigates to the route, so the initial bundle excludes code for unvisited pages.

  26. What is 'hydration' and how can lazy loading reduce its cost?

    Hydration attaches event listeners/interactivity to server-rendered HTML on the client. Lazy/partial hydration defers hydrating non-critical or off-screen components, reducing main-thread work and improving TTI.

  27. Why does React require a single root element (or fragment) when reconciling a component's output?

    Reconciliation diffs trees node by node; a component must return one tree root so React can consistently match and patch it. Fragments (<>...</>) let you return multiple children without adding an extra DOM node.

  28. What is the trade-off of over-splitting code into too many tiny chunks?

    Too many small chunks add network request overhead (HTTP round-trips, headers) and can hurt performance due to request waterfalls, offsetting the benefit of smaller payloads. Chunk sizes should be balanced.

  29. During reconciliation, what determines whether a component instance is preserved or recreated between renders?

    Its position in the tree and its element type (and key, for list children). If the type and position match, React preserves the instance and its state; if the type differs, it unmounts the old and mounts a new one.

  30. What is the difference between 'diffing' and 'patching' in a Virtual DOM cycle?

    Diffing computes the differences between the previous and new virtual trees (producing a list of changes); patching applies those computed changes to the real DOM. Diffing is analysis; patching is mutation.

Front-end Web Development Performance Optimization FAQ

What is in the Front-end Web Development Performance Optimization syllabus?

Front-end Web Development Performance Optimization is split into 2 chapters: Loading Optimization and Rendering Optimization. Together they contain 4 topics.

How many chapters are in Front-end Web Development Performance Optimization?

2 chapters, containing 4 topics. The largest chapter is Loading Optimization, with 2 topics.

Are there flashcards for Front-end Web Development Performance Optimization?

Yes — a 50-card Performance Optimization deck, printed in full in the flashcards section of this page and available in the Examius app with spaced repetition. The free plan covers one exam of your choice, including its flashcards; Examius Pro, a one-time purchase, unlocks every other exam and deck.