Expand description
The Cockpit’s static files, served from the distribution’s share/cockpit/.
Read once and kept: an asset is loaded from disk the first time it is asked for and answered from memory afterwards, with the digest of its bytes as its cache key. The digest is in the URL the pages emit, so a changed file is a changed URL and the browser’s cache never has to be told anything.
Only the URL a page emits is immutable: a request whose v is anything but the file’s
current version is answered no-cache, and every answer carries the digest as its
ETag, so a revalidation that still holds is a 304 with no body. A script module’s
relative imports are rewritten, when it is read, to the digested URLs of the modules
they name: a module’s digest then covers what it imports, so a change to cockpit.js
is a new URL for every module that imports it, and every importer names the one URL.
Nothing is compiled into the executable. share/ is where this tool keeps its data —
the kinds, the schemas, the allow-lists — and the Cockpit’s stylesheet and scripts are
more of the same, locatable per invocation and replaceable without a rebuild.
Structs§
- Assets
- A surface’s asset directory, with what has been read from it: the Cockpit’s
share/cockpit/under/cockpit/assets/, or another surface’s beside it (ADR 0135).
Constants§
- DIR
- The directory inside the share directory that holds the Cockpit’s files.
- IMMUTABLE
- How long a browser may keep an asset whose URL carries the right digest. A year: the URL changes when the bytes change, so the entry can never be wrong.
- PREFIX
- The URL prefix every asset is served under.
Functions§
- media_
type - The media type of a file name, when it is one the Cockpit serves.
- safe_
name - A relative path safe to join onto the asset root: no absolute segment, no
.., no empty segment, and nothing outside a conservative character set. - shared
- The digest cache shared by every router of the process, so two routers over one distribution read each file once between them.