[]previous and next page

ServerHead

The head of one server render: what useHead, <Title>, <Meta>, <Link>, <Style> and <Base> registered while the app rendered.

The head of one server render: what useHead, <Title>, <Meta>, <Link>, <Style> and <Base> registered while the app rendered. Pass it to a render function through its head option, then write ServerHead.html into the document's <head>.

Tags follow the same rules as in the browser: the last registration of an identity wins (title, meta by name, ...), append-only tags all stay. Every tag carries the marker the browser's head sink looks for, so the client adopts the server's elements instead of adding duplicates.

Import#

ts
import type { ServerHead } from "@shadow-js/web/server";

Signature#

ts
interface ServerHead {
  /** Registers tags. Used by `useHead`; the returned function removes them again. */
  add(tags: readonly NormalizedTag[]): () => void;
  /** Forgets every registration. Multi-pass renders call this before each pass. */
  clear(): void;
  /**
   * The markup of the winning tags, in registration order. With a `nonce`, every `<style>` carries
   * it, so the page's Content-Security-Policy (`style-src 'nonce-...'`) accepts the styles. Throws a
   * TypeError when the text of a style contains a closing style tag.
   *
   * @param options `nonce` is added to every `<style>`. Default: no options, so no nonce.
   */
  html(options?: { readonly nonce?: string }): string;
  /** The winning tags, for hosts that build the head themselves. */
  tags(): readonly NormalizedTag[];
}

Members#

Name Type Description
add add(tags: readonly NormalizedTag[]): () => void Registers tags. Used by useHead; the returned function removes them again.
clear clear(): void Forgets every registration. Multi-pass renders call this before each pass.
html html(options?: { readonly nonce?: string }): string The markup of the winning tags, in registration order. With a nonce, every <style> carries it, so the page's Content-Security-Policy (style-src 'nonce-...') accepts the styles. Throws a TypeError when the text of a style contains a closing style tag.
tags tags(): readonly NormalizedTag[] The winning tags, for hosts that build the head themselves.