Compression
This middleware allows dynamic compression for gzip & deflate if you your responses are bigger than 4kb. If you want to enable compression for static files only, please use the Compression setting inside the Static method.
Installation
- go get -u github.com/gofiber/compression
Signature
- compression.New(config ...Config) func(*fiber.Ctx)
Config
Property | Type | Description | Default |
---|---|---|---|
Filter | func(*Ctx) bool | Defines a function to skip middleware | nil |
Level | int | Level of compression, 0 , 1 , 2 , 3 , 4 | 0 |
- package main
- import
- "github.com/gofiber/fiber"
- "github.com/gofiber/compression"
- )
- func main() {
- app := fiber.New()
- app.Use(compression.New())
- app.Get("/", func(c *fiber.Ctx) {
- c.Send("Welcome!")
- })
- app.Listen(3000)
- }