Styles
This page covers stylesheet resources in Doors.
If generic resource syntax is new, start with Resources. This page focuses on what is specific to <style> and <link rel="stylesheet">.
Start
Most pages start with one of these:
- CSS written directly in the template: plain
<style>...</style> - CSS kept in a file, bytes, or string:
<link rel="stylesheet" href=(...)> - CSS already hosted somewhere: plain
href="..."
Examples:
<style>
h1 {
color: red;
}
</style>
<link
rel="stylesheet"
href=(doors.ResourceLocalFS("web/app.css"))>
<link rel="stylesheet" href="/assets/app.css">
Stylesheet Links
Use <link rel="stylesheet"> when the CSS comes from a file, bytes, a string, a handler, or a proxy:
<link
rel="stylesheet"
href=(doors.ResourceLocalFS("web/app.css"))>
Buildable stylesheet sources are:
doors.ResourceLocalFS("web/app.css")doors.ResourceFS(webFS, "app.css")doors.ResourceBytes(appCSS)doors.ResourceString(appCSS)
These go through the stylesheet pipeline and produce a stylesheet resource URL.
Shorthands work on href= too:
href=(appCSS)is treated likehref=(doors.ResourceBytes(appCSS))href=(func(w http.ResponseWriter, r *http.Request) { ... })is treated likehref=(doors.ResourceHandler(...))
Modifier syntax is often convenient when the whole tag exists just to serve that stylesheet:
<link rel="stylesheet" (doors.ResourceBytes(appCSS))/>
Other href forms are:
- plain string such as
"/assets/app.css"for an already-hosted URL doors.ResourceExternal("https://cdn.example.com/app.css")for an external URL that should also participate in CSP source collectiondoors.ResourceHandler(...),doors.ResourceHook(...), ordoors.ResourceProxy(...)for handler-backed and proxied stylesheet URLs
On stylesheet links, output behaves like this:
- omitted or
output="default": buildable sources go through the stylesheet pipeline output="minify": same, but minifiedoutput="raw": Doors leaves the original tag alone
That means output="raw" is mainly useful when href is already something the browser can use directly.
Attrs
These attrs control managed stylesheet behavior:
output:default,minify, orrawname: readable output file nameprivate: serve the stylesheet through an instance-scoped hook URL while still using the stylesheet pipelinenocache: serve through an instance-scoped hook URL without shared resource caching
Example:
<link
rel="stylesheet"
href=(doors.ResourceBytes(appCSS))
name="app.css"
private>
Plain string URLs are passed through as-is. Handler and proxy sources already produce hook-backed URLs. private and nocache are most useful with managed stylesheet resources.
Choose
- CSS written here for this page: plain
<style>...</style> - CSS kept in a file, bytes, or string:
<link rel="stylesheet" href=(...)> - Bytes already in memory:
href=(appCSS)orhref=(doors.ResourceBytes(appCSS)) - Already-hosted stylesheet: plain string
href - External stylesheet that should also be added to CSP:
ResourceExternal(...) - Literal browser
<style>tag:output="raw" - Minified managed stylesheet output:
output="minify" - Shared public stylesheet URL is not wanted: use
privateornocache