perf(web): cache static assets and defer wasm boot

Add long Cache-Control for /static, version client embed URLs from
asset_version, and delay WASM mount until after load so LCP images win.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-18 15:07:54 +08:00
1 parent 981d754133
commit 453321c8c2
5 files changed
+87 -15

No files matched your search

@@ -153,10 +153,35 @@ func clientEmbedScript(page map[string]any) string {
if wasm == "" {
wasm = "/static/marqdo_wasm.wasm"
}
ver := ""
if v, ok := page["asset_version"].(string); ok {
ver = strings.TrimSpace(v)
} else if v, ok := page["资源版本"].(string); ok {
ver = strings.TrimSpace(v)
}
if ver != "" {
bridge = withAssetQuery(bridge, ver)
wasm = withAssetQuery(wasm, ver)
source = withAssetQuery(source, ver)
}
return `<script type="module" src="` + esc(bridge) + `" data-mq-wasm="` + esc(wasm) +
`" data-mq-source-url="` + esc(source) + `"></script>`
}
func withAssetQuery(url, ver string) string {
if ver == "" || url == "" {
return url
}
if strings.Contains(url, "v=") {
return url
}
sep := "?"
if strings.Contains(url, "?") {
sep = "&"
}
return url + sep + "v=" + ver
}
var firstPBlockRe = regexp.MustCompile(`(?is)^(\s*)(<p\b[^>]*>)(.*?)(</p>)`)
func shouldDropcap(plain string) bool {
@@ -297,3 +297,23 @@ func TestNavBrandClientChrome(t *testing.T) {
t.Fatalf("missing drawer veil")
}
}
func TestClientEmbedAssetVersion(t *testing.T) {
page := map[string]any{
"title": "v",
"asset_version": "20260918d",
"client": map[string]any{
"source": "/static/client.mq.md",
},
}
html := render.RenderPage(page, "", "")
if !strings.Contains(html, `/static/marqdo-bridge.js?v=20260918d`) {
t.Fatalf("missing versioned bridge: %s", html)
}
if !strings.Contains(html, `data-mq-wasm="/static/marqdo_wasm.wasm?v=20260918d"`) {
t.Fatalf("missing versioned wasm")
}
if !strings.Contains(html, `data-mq-source-url="/static/client.mq.md?v=20260918d"`) {
t.Fatalf("missing versioned source")
}
}