font Serve Vazirmatn WOFF2 with explicit Content-Type headers
Test and publish / verify (push) Successful in 3m16s
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:
@@ -934,3 +934,36 @@ func extractCSRF(t *testing.T, body string) string {
|
||||
}
|
||||
return match[1]
|
||||
}
|
||||
|
||||
func TestStaticHandlerSetsFontContentTypes(t *testing.T) {
|
||||
s, err := New(Config{
|
||||
Addr: ":0",
|
||||
BaseURL: "http://example.test",
|
||||
DatabasePath: filepath.Join(t.TempDir(), "font.db"),
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer s.Close()
|
||||
|
||||
tests := []struct {
|
||||
path string
|
||||
want string
|
||||
}{
|
||||
{"/static/vendor/fonts/webfonts/Vazirmatn-400.ttf", "font/ttf"},
|
||||
{"/static/vendor/fonts/webfonts/Vazirmatn-Bold.woff2", "font/woff2"},
|
||||
{"/static/vendor/fontawesome.min.css", "text/css; charset=utf-8"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
req := httptest.NewRequest(http.MethodGet, tt.path, nil)
|
||||
rec := httptest.NewRecorder()
|
||||
s.http.Handler.ServeHTTP(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Errorf("%s: status %d", tt.path, rec.Code)
|
||||
continue
|
||||
}
|
||||
if ct := rec.Header().Get("Content-Type"); ct != tt.want {
|
||||
t.Errorf("%s: Content-Type = %q, want %q", tt.path, ct, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user