package templates import "sync" // Bundle versions: a short content hash per static JS bundle, set once // at server startup. Script tags render /static/.js?v=, // so any rebuild that changes a bundle's bytes automatically changes // its cache key — browsers fetch the new bundle with no manual stamp // bumps (the manual ?v=N stamp is exactly how a fixed search dropdown // stayed broken for one deploy: the HTML kept pointing at the old, // cached URL). // // An unset bundle renders ?v=0; the /static route also sends // Cache-Control: no-cache, so worst case browsers revalidate — the // hash is the fast path, not the correctness mechanism. var bundleVersionsMu sync.RWMutex var bundleVersions = map[string]string{} // SetBundleVersion records the content hash for a bundle ("main.js"). // Called once at startup for each built bundle. func SetBundleVersion(name, hash string) { bundleVersionsMu.Lock() defer bundleVersionsMu.Unlock() bundleVersions[name] = hash } // BundleVersion returns the recorded version for a bundle, or "0". func BundleVersion(name string) string { bundleVersionsMu.RLock() defer bundleVersionsMu.RUnlock() if v, ok := bundleVersions[name]; ok && v != "" { return v } return "0" } // MainJSVersion is the templ-side accessor for the main bundle stamp. func MainJSVersion() string { return BundleVersion("main.js") } // ReaderJSVersion is the templ-side accessor for the reader bundle stamp. func ReaderJSVersion() string { return BundleVersion("reader.js") }