1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-21 20:33:08 +00:00
fiber/middleware/favicon.md
2020-07-02 12:16:12 +02:00

979 B

Favicon

Favicon middleware ignores favicon requests or caches a provided icon in memory to improve performance by skipping disk access. User agents request favicon.ico frequently and indiscriminately, so you may wish to exclude these requests from your logs by using this middleware before your logger middleware.

Note This middleware is exclusively for serving the default, implicit favicon, which is GET /favicon.ico.

Example

Import the middleware package that is part of the Fiber web framework

import (
  "github.com/gofiber/fiber"
  "github.com/gofiber/fiber/middleware"
)

After you initiate your Fiber app, you can use the following possibilities:

func main() {
  app := fiber.New()
      
  // Default ignore favicon
  app.Use(middleware.Favicon())

  // Pass a favicon file that will be cached in memory
  app.Use(middleware.Favicon("./favicon.ico"))

  // ...
}

Signatures

func Favicon(file ...string) fiber.Handler {}