--- title: prerender --- `prerender` renders a React tree to a static HTML string using a [Web Stream](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API). ```js const {prelude, postponed} = await prerender(reactNode, options?) ``` This API depends on [Web Streams.](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) For Node.js, use [`prerenderToNodeStream`](/reference/react-dom/static/prerenderToNodeStream) instead. --- ## Reference {/*reference*/} ### `prerender(reactNode, options?)` {/*prerender*/} Call `prerender` to render your app to static HTML. ```js import { prerender } from 'react-dom/static'; async function handler(request, response) { const {prelude} = await prerender(, { bootstrapScripts: ['/main.js'] }); return new Response(prelude, { headers: { 'content-type': 'text/html' }, }); } ``` On the client, call [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) to make the server-generated HTML interactive. [See more examples below.](#usage) #### Parameters {/*parameters*/} * `reactNode`: A React node you want to render to HTML. For example, a JSX node like ``. It is expected to represent the entire document, so the App component should render the `` tag. * **optional** `options`: An object with static generation options. * **optional** `bootstrapScriptContent`: If specified, this string will be placed in an inline ` ``` On the client, your bootstrap script should [hydrate the entire `document` with a call to `hydrateRoot`:](/reference/react-dom/client/hydrateRoot#hydrating-an-entire-document) ```js [[1, 4, ""]] import { hydrateRoot } from 'react-dom/client'; import App from './App.js'; hydrateRoot(document, ); ``` This will attach event listeners to the static server-generated HTML and make it interactive. #### Reading CSS and JS asset paths from the build output {/*reading-css-and-js-asset-paths-from-the-build-output*/} The final asset URLs (like JavaScript and CSS files) are often hashed after the build. For example, instead of `styles.css` you might end up with `styles.123456.css`. Hashing static asset filenames guarantees that every distinct build of the same asset will have a different filename. This is useful because it lets you safely enable long-term caching for static assets: a file with a certain name would never change content. However, if you don't know the asset URLs until after the build, there's no way for you to put them in the source code. For example, hardcoding `"/styles.css"` into JSX like earlier wouldn't work. To keep them out of your source code, your root component can read the real filenames from a map passed as a prop: ```js {1,6} export default function App({ assetMap }) { return ( My app ... ); } ``` On the server, render `` and pass your `assetMap` with the asset URLs: ```js {1-5,8,9} // You'd need to get this JSON from your build tooling, e.g. read it from the build output. const assetMap = { 'styles.css': '/styles.123456.css', 'main.js': '/main.123456.js' }; async function handler(request) { const {prelude} = await prerender(, { bootstrapScripts: [assetMap['/main.js']] }); return new Response(prelude, { headers: { 'content-type': 'text/html' }, }); } ``` Since your server is now rendering ``, you need to render it with `assetMap` on the client too to avoid hydration errors. You can serialize and pass `assetMap` to the client like this: ```js {9-10} // You'd need to get this JSON from your build tooling. const assetMap = { 'styles.css': '/styles.123456.css', 'main.js': '/main.123456.js' }; async function handler(request) { const {prelude} = await prerender(, { // Careful: It's safe to stringify() this because this data isn't user-generated. bootstrapScriptContent: `window.assetMap = ${JSON.stringify(assetMap)};`, bootstrapScripts: [assetMap['/main.js']], }); return new Response(prelude, { headers: { 'content-type': 'text/html' }, }); } ``` In the example above, the `bootstrapScriptContent` option adds an extra inline `