Why this matters
Validators prevent unnecessary transfers while keeping clients fresh.
For Go static servers, set immutable Cache-Control for hashed files; otherwise set "Cache-Control: no-cache" and support conditional GET via ETag or Last-Modified using file info.
Validators prevent unnecessary transfers while keeping clients fresh.
Side-by-side examples engineers can pattern-match during review.
http.Handle("/", http.FileServer(http.Dir("./public"))) // no headershttp.HandleFunc("/", func(w http.ResponseWriter, r http.Request){ p := r.URL.Path; if hashRE.MatchString(p){ w.Header().Set("Cache-Control","public, max-age=31536000, immutable") } else { w.Header().Set("Cache-Control","no-cache"); w.Header().Set("ETag", etagFor(p)) } http.ServeFile(w, r, path.Join("public", p)) })w.Header().Set("Cache-Control","public, max-age=31536000, immutable")http.FileServer(http.Dir("./public")) // defaultFrom the same buckets as this rule.
All static JS/CSS/font/image files MUST use content-hashed filenames (e.g., app.9c1a7b.js) and be served with "Cache-Control: public, max-age=31536000, immutable". HTML and other non-fingerprinted documents MUST be served with "Cache-Control: no-cache" (or equivalent) to enable conditional revalidation.
Serve text-based assets (JS, CSS, JSON, SVG) with Brotli (br) when the client sends "Accept-Encoding: br" and fallback to gzip. Always set "Vary: Accept-Encoding" and do NOT compress already-compressed formats (e.g., .png, .jpg, .woff2).