Minify html on-the-fly before sending it to users

This commit is contained in:
Tom Wiesing 2023-01-04 12:45:33 +01:00
parent b3039768af
commit 785130dc36
No known key found for this signature in database
7 changed files with 66 additions and 6 deletions

View file

@ -17,10 +17,15 @@ func WriteHTML[T any](result T, err error, template *template.Template, template
w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusOK)
// minify html!
minifier := MinifyHTMLWriter(w)
defer minifier.Close()
// and return the template
if templateName != "" {
template.ExecuteTemplate(w, templateName, result)
template.ExecuteTemplate(minifier, templateName, result)
} else {
template.Execute(w, result)
template.Execute(minifier, result)
}
}