Developers

Prerender

Inject published body content and SEO into static HTML at build time so crawlers and first paint see finished pages.

Server-only secret
Prerender requires a secret in the environment (MACRO_SECRET_KEY by default) — never in macro.config.js or the browser bundle. See Keys model.

What gets injected

  • Live body values for marked data-macro-key nodes
  • Page SEO for data-macro-seo slots
  • data-macro-ssr="true" on stamped elements so the SDK skips the hydration flash

Vite plugin

Enable on the Vite plugin. Runs after vite build via closeBundle against outDir.

vite.config.ts
import { defineConfig } from 'vite'
import { macro } from '@macrocontent/sdk/vite'

export default defineConfig({
  plugins: [
    macro({
      config: '/macro.config.js',
      prerender: {
        enabled: true,
        locale: 'en',
        apiKeyEnv: 'MACRO_SECRET_KEY',
      },
    }),
  ],
})

CLI

For non-Vite pipelines or post-build steps, use the macro-prerender binary from @macrocontent/sdk:

bash
# From a site directory that has macro.config.js
pnpm exec macro-prerender . --out dist --locale en

Programmatic API: prerenderDirectory from @macrocontent/sdk/node (also fetchLiveValues, fetchPageSeo, injectLiveContentIntoHtml).

Options

NameTypeRequiredDescription
enabledbooleanoptionalVite: run after build when true.
localestringoptionalContent locale; falls back to defaultLocale in macro.config.js.
apiKeyEnvstringoptionalEnv var holding the server key. Default 'MACRO_SECRET_KEY'.
configFilestringoptionalPath to macro.config.js when not at the default location.

Publish first

  1. Edit in draft

    Editors change content in the overlay. Draft values are not what prerender reads.

  2. Publish to live

    Publish so Content API live reads see the new values. See Editors · Draft, live & publish.

  3. Rebuild

    Run your production build (or CI) with the secret set so HTML is stamped again.

Revalidate after publish
Many teams trigger a rebuild or cache purge from a publish webhook. Prerender itself is a build-time step — wire CI separately if you need instant crawler updates.

Offline exit

Leaving macrocontent entirely? Export a macrobundle and bake into static HTML without calling the API.