1. Docs
  2. Components
Edit on GitHub[]to change page

Head and SEO

<head> holds the elements for the page's head: title, meta tags, canonical link, OpenGraph, JSON-LD. Any component can use it. Static rendering moves its content into the page's head, and values that read state update in the browser when the state changes.

Lithe
<script kotlin>
	prop val post: Post
</script>

<head>
	<title>{post.title} - Blog</title>
	<meta name="description" content={post.summary}>
	<link rel="canonical" href={post.url}>
</head>

<article>...</article>

The pages of this site that are .lithe files, like the home page and the playground, set their title and description this way.

What it holds

  • <head> goes at the top level of the markup, outside every element and block, and takes no attribute. A condition goes inside it.
  • It holds <title>, <meta>, <link>, <script> and <style>, in @if, @when and @for blocks if needed, with @val. Those elements take text and attributes, no event, binding or spread. The component's <style> block doesn't apply to them.
  • <base> and <meta charset> go in resources/index.html, because the browser reads them before the rest of the head.
  • @await and @try aren't possible in <head>: put the <head> in a component inside them.

Which one wins

  • These elements replace one another: the <title>, a <meta> with the same name, property or http-equiv, and the canonical <link>. Their name, property, http-equiv and rel are constant.
  • When several components set the same one, the most deeply nested component wins, and between two components that don't contain each other, the last rendered one. The one component that wins keeps all its elements, so it can list several og:image, but a page has a single title. When it leaves, the one it replaced comes back.
  • The element of the page's template comes back too once no component sets its key, unless static rendering set that key: the build then takes the template's element out of the page, and bringing it back isn't possible yet because the browser never receives it.
  • Every other element is added as it is. It can't hold Kotlin values, which isn't possible yet because the browser finds the server element by its content.

In the page

A site build writes the winning elements at the end of the template's <head>, without the template's own elements of the same keys. In the browser, the server elements of a key are replaced by the client ones while hydrating, and an element without a key takes over the server element equal to it, so a script doesn't run twice.