In some situations we don't want to pre-render a page. For example a news page that displays the latest news fetched from a database should be rendered at request-time and certainly not at build-time.

We can use .page.server.js#noNoPrerender to tell Vike to skip a page from pre-rendering.

// /pages/

export const doNotPrerender = true

We can define doNotPrerender also in .page.js files, but not in .page.client.js files (because .page.client.js files are never loaded in Node.js).

We can define doNotPrerender in files.

For example, to make pre-rendering opt-in instead of opt-out:

// /renderer/

// By default, our pages are not pre-rendered
export const doNotPrerender = true
// /pages/

// Opt-in pre-rendering
export const doNotPrerender = false

This is especially handy with Domain-Driven File Structure:

// /pages/marketing/

// We use Domain-Driven File Structure and `` applies to
// all our marketing pages.

// Enable pre-rendering for all our marketing pages
export const doNotPrerender = false

Conditional pre-rendering

We can pre-render pages conditionally:

// /renderer/

export const doNotPrerender = isCmsPreview() ? true : false

This is particularly useful for previewing CMS pages (we don't want to pre-renderer a CMS preview deploy).

Note that prerender() hooks are always called, regardless of doNotPrerender. If we want to call prerender() hooks conditionally as well:

export const doNotPrerender = someCondition() ? true : false
export const prerender = doNotPrerender ? undefined : myPrerenderHook