Course contentsShow
← React
Lesson 1639 of 2,39640. Server-Side RenderingFree lesson

Server-Side HTML Structure and Scripts

Understanding the HTML output structure, including deferred script tags for progressive enhancement.

Server-Side HTML Structure and Scripts

What you'll learn: How React SSR generates HTML with strategically placed script tags for client-side hydration.

The HTML Output You Actually Get

When you render React on the server using renderToPipeableStream, you're not just sending raw HTML. The server generates a complete HTML document structure that includes:

  1. The initial HTML markup — your components rendered as static HTML
  2. Deferred script tags — JavaScript that will "wake up" the page on the client
  3. Inline data scripts — serialized props and state needed for hydration

Think of it like sending a flat-pack furniture kit: the HTML is the pre-assembled frame, and the script tags are the instructions and tools that let the client finish the job.

The Structure Pattern

<div id="root">
  <!-- Your rendered component HTML here -->
  <div>Hello, World!</div>
</div>

<!-- Deferred scripts load after HTML is visible -->
<script src="/static/js/main.chunk.js" defer></script>
<script src="/static/js/vendors.chunk.js" defer></script>

The defer attribute is critical: it tells the browser to download the script without blocking HTML parsing, then execute it after the document is ready.

Progressive Enhancement

This structure enables progressive enhancement: users see meaningful content immediately (the HTML), even if JavaScript hasn't loaded yet. As scripts load and execute, React "hydrates" the static HTML into an interactive app — attaching event listeners, activating state, and making it fully functional.

The server might also inject inline <script> tags containing serialized data (like fetched content or initial props) so the client doesn't need to re-fetch.

Key Takeaway: Server-rendered React outputs HTML with deferred script tags, enabling users to see content immediately while JavaScript progressively enhances the page into a fully interactive app.