Head Appender Functions

setHead()

Adds HTML to the head of the page.

Use it for markup that has to be in the head before the page renders, such as preload links and styles. Call it while the page renders on the server, so the markup is in the page's HTML. Markup added in the browser might not reach the page.

Throws when content contains a script tag, including encoded forms such as <script or %3Cscript. The check matches anywhere in the string, including attribute values and CSS text, and ignores case. It removes control characters before matching, so a script tag split by a control character, such as a null byte, still throws. When it throws, it adds nothing.

Adds the content as is. Apart from the script tag check, it doesn't escape or validate anything. The service passes every call on to the host and has no method to remove content, so add each piece of content once.

Method Declaration

Copy

Method Parameters

contentstringRequired

HTML to add to the head, such as one or more <link>, <meta>, or <style> elements. Escape any values you build into it.

Can't contain a script tag.


typeHeadContentType

Type of head content, which the host uses to decide where to place it.

Content of the default type reaches only search engine crawlers, not site visitors' browsers. For content that every site visitor's page needs, such as preload links and styles, specify HeadContentType.GENERAL.

Default: HeadContentType.AFTER_SECURITY

Examples

Last updated: 21 October 2026

Did this help?