Minify html on-the-fly before sending it to users
This commit is contained in:
parent
b3039768af
commit
785130dc36
7 changed files with 66 additions and 6 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue