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

  1. go get -u github.com/gofiber/compression

Signature

  1. compression.New(config ...Config) func(*fiber.Ctx)

Config

PropertyTypeDescriptionDefault
Filterfunc(*Ctx) boolDefines a function to skip middlewarenil
LevelintLevel of compression, 0, 1, 2, 3, 40
  1. package main
  2.  
  3. import
  4. "github.com/gofiber/fiber"
  5. "github.com/gofiber/compression"
  6. )
  7.  
  8. func main() {
  9. app := fiber.New()
  10.  
  11. app.Use(compression.New())
  12.  
  13. app.Get("/", func(c *fiber.Ctx) {
  14. c.Send("Welcome!")
  15. })
  16.  
  17. app.Listen(3000)
  18. }