Artifact 29682d2d7160a909c5cacd43e99d689a3d25a5220296cc415224896f4382ad40:
- File
internal/web/sheet_test.go
— part of check-in
[eb4793ee8e]
at
2026-08-31 15:49:44
on branch trunk
— serve the stylesheet instead of inlining it in every page
112,118 bytes of <style> rode on every response — 40% of a 309,584-byte timeline page, byte-identical each time and uncacheable because it had no URL, while the JS assets already carried Cache-Control. Now one hashed asset served immutable: a rule change mints a new URL, so a stale cache is impossible without anyone revalidating. (user: quarry, size: 1777) [annotate] [blame] [check-ins using]
package web import ( "strings" "testing" ) // The stylesheet is served, not inlined. It used to be 112,118 bytes of // <style> in every response — 40% of a 309,584-byte timeline page, // byte-identical each time and uncacheable because it had no URL. func TestSheetIsLinkedNotInlined(t *testing.T) { if strings.Contains(baseHTML, "<style>") { t.Error("the page still inlines a stylesheet") } if !strings.Contains(baseHTML, `rel="stylesheet"`) { t.Error("the page does not link a stylesheet") } if len(sheet) < 50_000 { t.Errorf("the sheet is %d bytes; the rules did not come with it", len(sheet)) } } // Both themes have to survive being moved out of the page — the whole // two-theme story lives in this one file, and chroma's half of it is // generated at startup rather than written down. func TestSheetCarriesBothThemes(t *testing.T) { for _, want := range []string{ "prefers-color-scheme: dark", `:root[data-theme="dark"]`, "--fg:", "--bg:", "--accent:", ".chroma", } { if !strings.Contains(sheet, want) { t.Errorf("the sheet is missing %q", want) } } } // The URL carries a content hash so it can be served immutable: a rule // change mints a new URL rather than asking anyone to revalidate. func TestSheetURLIsContentAddressed(t *testing.T) { if !strings.HasPrefix(sheetURL, "/assets/quarry.") || !strings.HasSuffix(sheetURL, ".css") { t.Fatalf("sheetURL = %q", sheetURL) } if h := sheetHash(); !strings.Contains(sheetURL, h) { t.Errorf("sheetURL %q does not carry the hash %q", sheetURL, h) } // Same content, same hash — the URL must be stable across a // restart or every deploy busts every reader's cache for nothing. if sheetHash() != sheetHash() { t.Error("the hash is not stable for identical content") } }