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 a direct browser 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 behavior is:
- omitted: buildable sources go through the stylesheet pipeline
raw: Doors leaves the original tag alone
Managed stylesheet output is minified by default. raw is mainly useful when href is already something the browser can use directly, or when an embedded <style> must stay literal.
Attrs
These attrs control managed stylesheet behavior:
raw: keep the stylesheet tag or link rawname: 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. doors.ResourceExternal(...) keeps the browser URL direct while also adding that host to CSP. Handler and proxy sources already produce hook-backed URLs.
Use private when the stylesheet should not be publicly reachable.
Use nocache for dynamically generated styles that should not use shared resource caching.