Back to Qwik

@builder.io/qwik/server API Reference

packages/docs/src/routes/api/qwik-server/index.mdx

1.7.117.3 KB
Original Source

API › @builder.io/qwik/server

<h2 id="getqwikloaderscript">getQwikLoaderScript</h2>

Provides the qwikloader.js file as a string. Useful for tooling to inline the qwikloader script into HTML.

typescript
export declare function getQwikLoaderScript(opts?: { debug?: boolean }): string;
<table><thead><tr><th>

Parameter

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

opts

</td><td>

{ debug?: boolean; }

</td><td>

(Optional)

</td></tr> </tbody></table>

Returns:

string

Edit this section

<h2 id="getqwikprefetchworkerscript">getQwikPrefetchWorkerScript</h2>

Provides the qwik-prefetch-service-worker.js file as a string. Useful for tooling to inline the qwik-prefetch-service-worker script into HTML.

typescript
export declare function getQwikPrefetchWorkerScript(opts?: {
  debug?: boolean;
}): string;
<table><thead><tr><th>

Parameter

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

opts

</td><td>

{ debug?: boolean; }

</td><td>

(Optional)

</td></tr> </tbody></table>

Returns:

string

Edit this section

<h2 id="inorderauto">InOrderAuto</h2>
typescript
export interface InOrderAuto
<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

maximunChunk?

</td><td> </td><td>

number

</td><td>

(Optional)

</td></tr> <tr><td>

maximunInitialChunk?

</td><td> </td><td>

number

</td><td>

(Optional)

</td></tr> <tr><td>

strategy

</td><td> </td><td>

'auto'

</td><td> </td></tr> </tbody></table>

Edit this section

<h2 id="inorderdisabled">InOrderDisabled</h2>
typescript
export interface InOrderDisabled
<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

strategy

</td><td> </td><td>

'disabled'

</td><td> </td></tr> </tbody></table>

Edit this section

<h2 id="inorderstreaming">InOrderStreaming</h2>
typescript
export type InOrderStreaming = InOrderAuto | InOrderDisabled | InOrderDirect;

References: InOrderAuto, InOrderDisabled

Edit this section

<h2 id="prefetchimplementation">PrefetchImplementation</h2>

Warning: This API is now obsolete.

Use preloader instead

typescript
export interface PrefetchImplementation
<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

linkFetchPriority?

</td><td> </td><td>

'auto' | 'low' | 'high' | null

</td><td>

(Optional)

</td></tr> <tr><td>

linkInsert?

</td><td> </td><td>

'js-append' | 'html-append' | null

</td><td>

(Optional)

</td></tr> <tr><td>

linkRel?

</td><td> </td><td>

'prefetch' | 'preload' | 'modulepreload' | null

</td><td>

(Optional)

</td></tr> <tr><td>

prefetchEvent?

</td><td> </td><td>

'always' | null

</td><td>

(Optional)

</td></tr> <tr><td>

workerFetchInsert?

</td><td> </td><td>

'always' | 'no-link-support' | null

</td><td>

(Optional)

</td></tr> </tbody></table>

Edit this section

<h2 id="prefetchresource">PrefetchResource</h2>
typescript
export interface PrefetchResource
<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

imports

</td><td> </td><td>

PrefetchResource[]

</td><td> </td></tr> <tr><td>

url

</td><td> </td><td>

string

</td><td> </td></tr> </tbody></table>

Edit this section

<h2 id="prefetchstrategy">PrefetchStrategy</h2>
typescript
export interface PrefetchStrategy
<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

implementation?

</td><td> </td><td>

PrefetchImplementation

</td><td>

(Optional)

</td></tr> <tr><td>

symbolsToPrefetch?

</td><td> </td><td>

SymbolsToPrefetch

</td><td>

(Optional)

</td></tr> </tbody></table>

Edit this section

<h2 id="preloaderoptions">PreloaderOptions</h2>
typescript
export interface PreloaderOptions
<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

debug?

</td><td> </td><td>

boolean

</td><td>

(Optional) Log preloader debug information to the console.

Defaults to false

</td></tr> <tr><td>

maxIdlePreloads?

</td><td> </td><td>

number

</td><td>

(Optional) Maximum number of simultaneous preload links that the preloader will maintain. If you set this higher, the browser will have all JS files in memory sooner, but it will contend with other resource downloads. Furthermore, if a bundle suddenly becomes more likely, it will have to wait longer to be preloaded.

Bundles that reach 100% probability (static imports of other bundles) will always be preloaded immediately, no limit.

Defaults to 25

</td></tr> <tr><td>

preloadProbability?

</td><td> </td><td>

number

</td><td>

(Optional)

</td></tr> <tr><td>

ssrPreloadProbability?

</td><td> </td><td>

number

</td><td>

(Optional) The minimum probability for a bundle to be added as a preload link during SSR.

Defaults to 0.7 (70% probability)

This makes sure that the most likely bundles are preloaded ahead of time.

</td></tr> <tr><td>

ssrPreloads?

</td><td> </td><td>

number

</td><td>

(Optional) Maximum number of preload links to add during SSR. These instruct the browser to preload likely bundles before the preloader script is active. This most likely includes the core and the preloader script itself. Setting this to 0 will disable all preload links.

Preload links can delay LCP, which is a Core Web Vital, but it can increase TTI, which is not a Core Web Vital but more noticeable to the user.

Defaults to 5

</td></tr> </tbody></table>

Edit this section

<h2 id="qwikloaderoptions">QwikLoaderOptions</h2>
typescript
export type QwikLoaderOptions =
  | "module"
  | "inline"
  | "never"
  | {
      include?: "always" | "never" | "auto";
      position?: "top" | "bottom";
    };

Edit this section

<h2 id="render">Render</h2>
typescript
export type Render = RenderToString | RenderToStream;

References: RenderToString, RenderToStream

Edit this section

<h2 id="renderoptions">RenderOptions</h2>
typescript
export interface RenderOptions extends SerializeDocumentOptions

Extends: SerializeDocumentOptions

<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

base?

</td><td> </td><td>

string | ((options: RenderOptions) => string)

</td><td>

(Optional) Specifies the root of the JS files of the client build. Setting a base, will cause the render of the q:base attribute in the q:container element.

</td></tr> <tr><td>

containerAttributes?

</td><td> </td><td>

Record<string, string>

</td><td>

(Optional)

</td></tr> <tr><td>

containerTagName?

</td><td> </td><td>

string

</td><td>

(Optional) When set, the app is serialized into a fragment. And the returned html is not a complete document. Defaults to html

</td></tr> <tr><td>

locale?

</td><td> </td><td>

string | ((options: RenderOptions) => string)

</td><td>

(Optional) Language to use when rendering the document.

</td></tr> <tr><td>

prefetchStrategy?

</td><td> </td><td>

PrefetchStrategy | null

</td><td>

(Optional)

</td></tr> <tr><td>

preloader?

</td><td> </td><td>

PreloaderOptions | false

</td><td>

(Optional) Specifies how preloading is handled. This ensures that code is instantly available when needed.

</td></tr> <tr><td>

qwikLoader?

</td><td> </td><td>

QwikLoaderOptions

</td><td>

(Optional) Specifies how the Qwik Loader is included in the document. This enables interactivity and lazy loading.

module: Use a <script> tag to load the Qwik Loader. Subsequent page loads will have the script cached and instantly running.

inline: This embeds the Qwik Loader script directly in the document. This adds about 3kB before compression, which typically is reduced to about 1.6kB with gzip.

never: Do not include the Qwik Loader script. This is mostly useful when embedding multiple containers on the same page.

Defaults to module.

Note that the Qwik Loader is absolutely required for Qwik to work. There must be an instance of it loaded for any interactivity to happen.

</td></tr> <tr><td>

qwikPrefetchServiceWorker?

</td><td> </td><td>

QwikPrefetchServiceWorkerOptions

</td><td>

(Optional)

</td></tr> <tr><td>

serverData?

</td><td> </td><td>

Record<string, any>

</td><td>

(Optional)

</td></tr> <tr><td>

snapshot?

</td><td> </td><td>

boolean

</td><td>

(Optional) Defaults to true

</td></tr> </tbody></table>

Edit this section

<h2 id="renderresult">RenderResult</h2>
typescript
export interface RenderResult
<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

isStatic

</td><td> </td><td>

boolean

</td><td> </td></tr> <tr><td>

manifest?

</td><td> </td><td>

ServerQwikManifest

</td><td>

(Optional)

</td></tr> <tr><td>

prefetchResources

</td><td> </td><td>

PrefetchResource[]

</td><td> </td></tr> <tr><td>

snapshotResult

</td><td> </td><td>

SnapshotResult | undefined

</td><td> </td></tr> </tbody></table>

Edit this section

<h2 id="rendertostream-function">renderToStream</h2>
typescript
export type RenderToStream = (
  opts: RenderToStreamOptions,
) => Promise<RenderToStreamResult>;

References: RenderToStreamOptions, RenderToStreamResult

Edit this section

<h2 id="rendertostream-type-alias">RenderToStream</h2>
typescript
export type RenderToStream = (
  opts: RenderToStreamOptions,
) => Promise<RenderToStreamResult>;

References: RenderToStreamOptions, RenderToStreamResult

Edit this section

<h2 id="rendertostreamoptions">RenderToStreamOptions</h2>
typescript
export interface RenderToStreamOptions extends RenderOptions

Extends: RenderOptions

<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

stream

</td><td> </td><td>

StreamWriter

</td><td> </td></tr> <tr><td>

streaming?

</td><td> </td><td>

StreamingOptions

</td><td>

(Optional)

</td></tr> </tbody></table>

Edit this section

<h2 id="rendertostreamresult">RenderToStreamResult</h2>
typescript
export interface RenderToStreamResult extends RenderResult

Extends: RenderResult

<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

flushes

</td><td> </td><td>

number

</td><td> </td></tr> <tr><td>

size

</td><td> </td><td>

number

</td><td> </td></tr> <tr><td>

timing

</td><td> </td><td>

{ firstFlush: number; render: number; snapshot: number; }

</td><td> </td></tr> </tbody></table>

Edit this section

<h2 id="rendertostring-function">renderToString</h2>
typescript
export type RenderToString = (
  opts: RenderToStringOptions,
) => Promise<RenderToStringResult>;

References: RenderToStringOptions, RenderToStringResult

Edit this section

<h2 id="rendertostring-type-alias">RenderToString</h2>
typescript
export type RenderToString = (
  opts: RenderToStringOptions,
) => Promise<RenderToStringResult>;

References: RenderToStringOptions, RenderToStringResult

Edit this section

<h2 id="rendertostringoptions">RenderToStringOptions</h2>
typescript
export interface RenderToStringOptions extends RenderOptions

Extends: RenderOptions

Edit this section

<h2 id="rendertostringresult">RenderToStringResult</h2>
typescript
export interface RenderToStringResult extends RenderResult

Extends: RenderResult

<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

html

</td><td> </td><td>

string

</td><td> </td></tr> <tr><td>

timing

</td><td> </td><td>

{ render: number; snapshot: number; }

</td><td> </td></tr> </tbody></table>

Edit this section

<h2 id="resolvemanifest">resolveManifest</h2>

Merges a given manifest with the built manifest and provides mappings for symbols.

typescript
export declare function resolveManifest(
  manifest?: Partial<QwikManifest | ResolvedManifest> | undefined,
): ResolvedManifest | undefined;
<table><thead><tr><th>

Parameter

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

manifest

</td><td>

Partial<QwikManifest | ResolvedManifest> | undefined

</td><td>

(Optional)

</td></tr> </tbody></table>

Returns:

ResolvedManifest | undefined

Edit this section

<h2 id="serializedocumentoptions">SerializeDocumentOptions</h2>
typescript
export interface SerializeDocumentOptions
<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

debug?

</td><td> </td><td>

boolean

</td><td>

(Optional)

</td></tr> <tr><td>

manifest?

</td><td> </td><td>

Partial<QwikManifest | ResolvedManifest>

</td><td>

(Optional)

</td></tr> <tr><td>

symbolMapper?

</td><td> </td><td>

SymbolMapperFn

</td><td>

(Optional)

</td></tr> </tbody></table>

Edit this section

<h2 id="setserverplatform">setServerPlatform</h2>
typescript
export declare function setServerPlatform(
  manifest?: Partial<QwikManifest | ResolvedManifest>,
): Promise<void>;
<table><thead><tr><th>

Parameter

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

manifest

</td><td>

Partial<QwikManifest | ResolvedManifest>

</td><td>

(Optional)

</td></tr> </tbody></table>

Returns:

Promise<void>

Edit this section

<h2 id="streamingoptions">StreamingOptions</h2>
typescript
export interface StreamingOptions
<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

inOrder?

</td><td> </td><td>

InOrderStreaming

</td><td>

(Optional)

</td></tr> </tbody></table>

Edit this section

<h2 id="symbolstoprefetch">SymbolsToPrefetch</h2>

Auto: Prefetch all possible QRLs used by the document. Default

typescript
export type SymbolsToPrefetch =
  | "auto"
  | ((opts: { manifest: ServerQwikManifest }) => PrefetchResource[]);

References: PrefetchResource

Edit this section

<h2 id="versions">versions</h2>
typescript
versions: {
    readonly qwik: string;
    readonly qwikDom: string;
}

Edit this section