Bird
Raised Fist0
Vueframework~8 mins

Static site generation with Nuxt in Vue - Performance & Optimization

Choose your learning style10 modes available
Performance: Static site generation with Nuxt
HIGH IMPACT
Static site generation improves page load speed by pre-building HTML pages, reducing server work and client rendering time.
Delivering fast initial page load for a Vue app
Vue
export default { target: 'static', ssr: true /* enable static site generation */ }
Pages are pre-rendered to static HTML at build time, so browsers show content immediately.
📈 Performance GainReduces LCP by up to 70%; no JS needed for initial paint; faster time to interactive.
Delivering fast initial page load for a Vue app
Vue
export default { ssr: false /* client-side rendering only */ }
Pages are rendered on the client, causing slower initial load and higher CPU use on user devices.
📉 Performance CostBlocks rendering until JS loads and runs; increases LCP by 1-3 seconds on slow networks.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Client-side rendering onlyMany DOM updates after JS loadsMultiple reflows during hydrationHigh paint cost due to delayed content[X] Bad
Static site generation with NuxtMinimal DOM updates on loadSingle reflow on initial paintLow paint cost with immediate content[OK] Good
Rendering Pipeline
Static site generation outputs ready HTML files, so the browser skips server rendering and heavy JS execution for first paint.
→HTML Parsing
→Style Calculation
→Layout
→Paint
⚠️ BottleneckServer-side rendering at request time is eliminated, reducing server response delays.
Core Web Vital Affected
LCP
Static site generation improves page load speed by pre-building HTML pages, reducing server work and client rendering time.
Optimization Tips
1Pre-build pages to serve static HTML and reduce server response delays.
2Avoid client-only rendering for main content to improve LCP.
3Use Nuxt's static target to minimize JavaScript blocking initial paint.
Performance Quiz - 3 Questions
Test your performance knowledge
How does static site generation with Nuxt affect Largest Contentful Paint (LCP)?
AIt delays LCP because pages render on the client.
BIt has no effect on LCP.
CIt improves LCP by serving pre-built HTML quickly.
DIt worsens LCP by adding extra server processing.
DevTools: Performance
How to check: Record page load and look for time to first contentful paint and scripting time.
What to look for: Short time to first contentful paint and minimal scripting blocking indicate good static generation.

Practice

(1/5)
1. What does static site generation (SSG) in Nuxt do before users visit the site?
easy
A. Requires a server to render pages on demand
B. Generates pages dynamically on each user request
C. Builds all pages ahead of time as static files
D. Only builds the homepage statically

Solution

  1. Step 1: Understand static site generation concept

    Static site generation means creating all pages before users visit, so they are ready as static files.
  2. Step 2: Apply to Nuxt behavior

    Nuxt with static target builds all pages ahead, not on demand or partially.
  3. Final Answer:

    Builds all pages ahead of time as static files -> Option C
  4. Quick Check:

    SSG = Pre-build pages [OK]
Hint: SSG means pre-building pages before user visits [OK]
Common Mistakes:
  • Confusing static generation with server-side rendering
  • Thinking pages build on each request
  • Assuming only homepage is static
2. Which Nuxt configuration option enables static site generation?
easy
A. target: 'static'
B. mode: 'universal'
C. ssr: false
D. buildModules: ['@nuxt/static']

Solution

  1. Step 1: Identify Nuxt config for static generation

    Nuxt uses target: 'static' to enable static site generation.
  2. Step 2: Check other options

    ssr: false disables server-side rendering but does not enable static generation; mode is deprecated; buildModules with '@nuxt/static' is invalid.
  3. Final Answer:

    target: 'static' -> Option A
  4. Quick Check:

    Static target = 'static' [OK]
Hint: Look for target set to 'static' in config [OK]
Common Mistakes:
  • Using ssr: false instead of target: 'static'
  • Confusing mode with target
  • Assuming buildModules enables static
3. Given this Nuxt config snippet, what will be the output folder after running nuxt generate?
export default {
  target: 'static',
  generate: {
    dir: 'public'
  }
}
medium
A. A folder named 'build' will be created
B. A folder named 'dist' will be created
C. No folder will be created automatically
D. A folder named 'public' will be created

Solution

  1. Step 1: Understand generate.dir option

    The generate.dir option sets the output folder for static files.
  2. Step 2: Apply config values

    Since dir: 'public' is set, the static files will be generated inside a folder named 'public'.
  3. Final Answer:

    A folder named 'public' will be created -> Option D
  4. Quick Check:

    generate.dir = output folder [OK]
Hint: generate.dir sets output folder name [OK]
Common Mistakes:
  • Assuming default 'dist' folder is always used
  • Confusing generate.dir with buildDir
  • Thinking no folder is created
4. You run nuxt generate but your dynamic routes are missing from the static site. What is the likely cause?
medium
A. You forgot to add the dynamic routes in generate.routes
B. You set target to 'server' instead of 'static'
C. You did not install the Nitro preset
D. You used ssr: false in config

Solution

  1. Step 1: Understand dynamic routes in static generation

    Nuxt needs explicit dynamic routes listed in generate.routes to pre-build them.
  2. Step 2: Check other options

    target: 'server' disables static generation but does not explain missing dynamic routes if static is used; Nitro preset is internal; ssr: false disables SSR but not related to dynamic routes generation.
  3. Final Answer:

    You forgot to add the dynamic routes in generate.routes -> Option A
  4. Quick Check:

    Dynamic routes need generate.routes [OK]
Hint: Add dynamic routes in generate.routes to include them [OK]
Common Mistakes:
  • Assuming dynamic routes are auto-detected
  • Confusing ssr: false with static target
  • Thinking Nitro preset fixes missing routes
5. You want to build a blog with Nuxt static generation. Your posts are fetched from an API at build time. Which approach correctly generates static pages for each post?
hard
A. Fetch posts only on client side with mounted() and rely on client rendering
B. Use asyncData to fetch posts and list them, then add dynamic routes in generate.routes to pre-build each post page
C. Set ssr: false and generate pages dynamically on server
D. Use fetch() in components without configuring generate.routes

Solution

  1. Step 1: Fetch posts at build time

    Using asyncData fetches posts during build, enabling static generation.
  2. Step 2: Configure dynamic routes for posts

    Adding post URLs in generate.routes tells Nuxt to pre-build each post page as static HTML.
  3. Step 3: Evaluate other options

    Client-side fetching delays content and is not static; ssr: false disables server rendering; fetch() without generate.routes won't pre-build dynamic pages.
  4. Final Answer:

    Use asyncData and generate.routes to pre-build each post page -> Option B
  5. Quick Check:

    asyncData + generate.routes = static dynamic pages [OK]
Hint: Use asyncData and generate.routes for static dynamic pages [OK]
Common Mistakes:
  • Fetching posts only on client side
  • Not adding dynamic routes in generate.routes
  • Disabling SSR with ssr: false
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard