deployid

command
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Command deployid echoes a deploy identifier from the environment into a meta tag, and says when it could not put it somewhere a browser will read.

$ DEPLOY_ID=d7f3a91 deployid page.html
<!doctype html><meta name="deploy-id" content="d7f3a91"><html><head>…

$ DEPLOY_ID=d7f3a91 deployid -report page.html
the meta is in the head
  anchor            before the first element, <html>
  head reached      yes

A comment can go anywhere. A meta has to be in the head or a browser ignores it, and a rewriter cannot see the head that a parser will build - see examples/gip/buildinfo and B182. So the question is not where to put the tag but whether the place available is a place that counts.

The parser builds the head around the insertion, unless text got there first

Inserting a bare meta before the first element is enough: a parser in its "before head" mode meets the meta, creates the head, and puts the meta in it. Wrapping the meta in <head> of your own is unnecessary, and harmless where the source has a head already, because a second head is a parse error and dropped. Measured against x/net/html:

document                                    the meta lands
<!doctype html><html><head>…                in the head
<!doctype html><p>x</p>                     in the head - the parser creates one
<!doctype html><html><body><p>x</p>…        in the head
<!doctype html><body><p>x</p>               in the head
<!doctype html><title>t</title><p>x</p>     in the head, before the title
<!doctype html><!-- c --><p>x</p>           in the head
<!doctype html>\n  <p>x</p>                 in the head
<!doctype html>text<p>x</p>                 in the *body*, where it is ignored
<!doctype html>&nbsp;<p>x</p>               in the body: nbsp is not whitespace
just text                                   in the body

So the rule is: the meta reaches the head if nothing but the doctype, comments and whitespace precedes the insertion point. The two failures are the same failure - text before the first element ends the head, and a document that is only text has no first element at all.

The non-breaking space is worth its own line. It looks like whitespace, it is not one of the five characters a parser skips before the head, and a template that indents its output with one by accident moves every meta tag into the body.

And that is detectable, in one pass, before the insertion

Text arrives before the element that follows it, so a text handler knows whether the head is still open by the time the element handler runs. This program uses that: it counts non-whitespace text seen before the first element, inserts the meta anyway - a meta in the body is inert rather than harmful - and reports that a browser will ignore it. Reporting beats silence: a deploy id that is present in the source and invisible to the tooling that reads it is worse than one that is missing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL