https://github.com/beyer-stefan/gofiber-minifier
HTML, JavaScript, and CSS minifier for the gofiber-Framework
https://github.com/beyer-stefan/gofiber-minifier
go gofiber golang minifier minify minify-css minify-html minify-javascript web
Last synced: 21 days ago
JSON representation
HTML, JavaScript, and CSS minifier for the gofiber-Framework
- Host: GitHub
- URL: https://github.com/beyer-stefan/gofiber-minifier
- Owner: beyer-stefan
- License: mit
- Created: 2024-02-06T07:21:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-25T10:50:40.000Z (about 1 year ago)
- Last Synced: 2024-03-25T22:25:44.085Z (about 1 year ago)
- Topics: go, gofiber, golang, minifier, minify, minify-css, minify-html, minify-javascript, web
- Language: Go
- Homepage:
- Size: 19.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-fiber - beyer-stefan/gofiber-minifier - Minifying middleware for HTML5, CSS3, and JavaScript. (⚙️ Middlewares / 🌱 Third Party)
README
# gofiber-minifier
## Introduction
Minifier for [Fiber ("gofiber")](https://github.com/gofiber) supporting HTML5, CSS3, and JavaScript.> **Fiber** is an [Express](https://github.com/expressjs/express) inspired **web framework** built on top of [Fasthttp](https://github.com/valyala/fasthttp), the **fastest** HTTP engine for [Go](https://golang.org/doc/). Designed to **ease** things up for **fast** development with **zero memory allocation** and **performance** in mind.
> Minification is the process of removing characters like whitespaces, tab stops, or CR/LR from files without changing their meaning, ultimately shrinking file size and speeding up transmission over the internet.
## Install
```Shell
go get github.com/beyer-stefan/gofiber-minifier
```## Usage
```Golang
package mainimport (
"github.com/gofiber/fiber"
"github.com/beyer-stefan/gofiber-minifier"
)func main() {
app := fiber.New()
(...)
app.Use(minifier.New(minifier.Config{
MinifyHTML: true,
}))
// static files ...
// application routes ...
(...)
}
```### Handling Warn messages
If you put the minifier before your static content and your application routes
you will most likely see warning messages similar to this one:
```
(...) minifier.go:77: [Warn] minifier does not exist for mimetype 'image/jpeg'
```
This is because not all mimetypes can be minified. If e.g. your static files
consist of JPG-images and CSS, you will get a warning message similar to one shown above
for all JPG-images. This can be handled in two ways:
1. Find the right position in your code so you only minify supported mimetyes
2. Use `SuppressWarnings` to get rid of the Warn messages
```
app.Use(minifier.New(minifier.Config{
SuppressWarnings: true,
MinifyHTML: true,
MinifyCSS: true,
}))
```## Credits
This project is a thin wrapper on top of [minify](https://github.com/tdewolff/minify) by [Taco de Wolff](https://github.com/tdewolff).
He deserves all the credit.## License
Released under the [MIT license](LICENSE.md).[](https://app.codacy.com/gh/beyer-stefan/gofiber-minifier/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[](https://goreportcard.com/badge/github.com/beyer-stefan/gofiber-minifier)
[](https://github.com/gofiber/awesome-fiber)