-
Notifications
You must be signed in to change notification settings - Fork 2
Minify Template
Thanatat Tamtan edited this page Sep 23, 2023
·
3 revisions
Hime can minify HTML, CSS, and JavaScript inside template using tdewolff/minify
package main
import (
"log"
"github.com/moonrhythm/hime"
)
func main() {
app := hime.New()
t := app.Template()
t.Minify()
t.Parse("index", `
<!doctype html>
<html>
<head>
<title>Hime</title>
<style>
h1 {
color: blue;
}
</style>
</head>
<body>
<h1>Hello, {{.Name}}</h1>
<script>
alert('Hello, {{.Name}}')
</script>
</body>
</html>
`)
app.Handler(hime.Handler(index))
app.Address(":8080")
err := app.ListenAndServe()
if err != nil {
log.Fatal(err)
}
}
func index(ctx *hime.Context) error {
return ctx.View("index", map[string]any{
"Name": "Hime",
})
}Output
<!doctype html><title>Hime</title><style>h1{color:blue}</style><h1>Hello, Hime</h1><script>alert('Hello, Hime')</script>