font Serve Vazirmatn WOFF2 with explicit Content-Type headers
Test and publish / verify (push) Successful in 3m16s

Switch Vazirmatn font-face from TTF-only to WOFF2 to halve the
font payload (~50 KB vs ~105 KB per weight). Add a staticHandler
middleware that injects font/ttf and font/woff2 Content-Type headers
so browsers don't reject them as application/octet-stream.
This commit is contained in:
2026-08-06 17:39:54 +03:30
parent f6577a24e6
commit 7e8b7c4343
3 changed files with 64 additions and 10 deletions
+19 -1
View File
@@ -267,8 +267,26 @@ func (s *Server) ListenAndServe() error {
func (s *Server) Close() error { return s.store.Close() }
// staticHandler wraps a file server so font files always get the correct
// Content-Type — Go's http.DetectContentType can return application/octet-stream
// for .ttf files on older Go versions.
func staticHandler(fs http.FileSystem) http.Handler {
h := http.FileServer(fs)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
path := strings.TrimPrefix(r.URL.Path, "/static/")
switch {
case strings.HasSuffix(path, ".ttf"):
w.Header().Set("Content-Type", "font/ttf")
case strings.HasSuffix(path, ".woff"), strings.HasSuffix(path, ".woff2"):
w.Header().Set("Content-Type", "font/woff2")
}
h.ServeHTTP(w, r)
})
}
func (s *Server) routes(mux *http.ServeMux) {
mux.Handle("GET /static/", http.FileServer(http.FS(assets)))
fs := http.FS(assets)
mux.Handle("GET /static/", staticHandler(fs))
mux.Handle("GET /uploads/avatars/", http.StripPrefix("/uploads/avatars/", http.FileServer(http.Dir(filepath.Join(filepath.Dir(s.cfg.DatabasePath), "avatars")))))
mux.HandleFunc("GET /healthz", s.health)
mux.HandleFunc("GET /login", s.loginPage)