liveBook · Manning

Metadata

As explained in Vanilla Web

Metadata is information that defines settings and descriptive properties for a website or web application without changing the document contents displayed in the viewport.

Web metadata configures how a browser and surrounding services present a site without changing the content displayed in the viewport. Use it to set the page title, icons, theme color, viewport behavior, manifest, and semantic or social information. section 3.3 section 3.9

Keep metadata accurate on every HTML document. During same-document route changes, update the title and active navigation state; set canonical URLs for indexable public pages. Social sharing metadata is best served with the page, since social apps may not read updates made in an existing browser session. section 3.9 section 11.1.3

function updateRouteMetadata({ title, canonicalPath }) {
  document.title = title;

  if (!canonicalPath) return;

  let canonical = document.querySelector('link[rel="canonical"]');
  if (!canonical) {
    canonical = document.createElement("link");
    canonical.rel = "canonical";
    document.head.append(canonical);
  }

  canonical.href = new URL(canonicalPath, location.origin).href;
}

A small helper updates the document title and creates or updates a canonical link when a route supplies a canonical path. section 11.1.3

How Vanilla Web covers it

How deep it goes
Defines core metadata settings and route updates, while deferring social-sharing metadata to server responses when needed.
Examples
Names titles, icons, theme color, viewport settings, manifests, OpenGraph data, and canonical links.
What you can do after
Configure document titles and canonical links during same-document navigation using native document APIs.
How it connects
Connects metadata to client-side routing, canonical URLs, semantic HTML, and web app manifests.

Also explained in

Compare how 23 books explain metadata →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Vanilla Web. The section links point to the parts of the book it draws on.