HTML Minifier for Go
Free online html minifier with Go code examples
Working with html minifier in Go? Our free online html minifier helps Go developers format, validate, and process data instantly. Below you will find Go code examples using github.com/tdewolff/minify so you can achieve the same result programmatically in your own projects.
Try the HTML Minifier Online
Use our free HTML Minifier directly in your browser — no setup required.
Open HTML MinifierGo Code Example
package main
import (
"fmt"
"github.com/tdewolff/minify/v2"
"github.com/tdewolff/minify/v2/html"
)
func main() {
m := minify.New()
m.AddFunc("text/html", html.Minify)
input := `<!DOCTYPE html>
<html>
<head><title>Hello</title></head>
<body>
<!-- comment -->
<h1>Hello World</h1>
<p>Welcome to my site.</p>
</body>
</html>`
output, _ := m.String("text/html", input)
fmt.Println(output)
}Quick Setup
Library: github.com/tdewolff/minify
go get github.com/tdewolff/minify/v2Go Tips & Best Practices
- tdewolff/minify handles HTML, CSS, JS, JSON, SVG, and XML
- One of the fastest HTML minifiers available
- Use m.Add for combining multiple minifiers