github.com/gofiber/fiber/v2@v2.47.0/docs/api/middleware/favicon.md (about)

     1  ---
     2  id: favicon
     3  title: Favicon
     4  ---
     5  
     6  Favicon middleware for [Fiber](https://github.com/gofiber/fiber) that 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.
     7  
     8  :::note
     9  This middleware is exclusively for serving the default, implicit favicon, which is GET /favicon.ico or [custom favicon URL](#config).
    10  :::
    11  
    12  ## Signatures
    13  
    14  ```go
    15  func New(config ...Config) fiber.Handler
    16  ```
    17  
    18  ## Examples
    19  
    20  Import the middleware package that is part of the Fiber web framework
    21  
    22  ```go
    23  import (
    24    "github.com/gofiber/fiber/v2"
    25    "github.com/gofiber/fiber/v2/middleware/favicon"
    26  )
    27  ```
    28  
    29  After you initiate your Fiber app, you can use the following possibilities:
    30  
    31  ```go
    32  // Initialize default config
    33  app.Use(favicon.New())
    34  
    35  // Or extend your config for customization
    36  app.Use(favicon.New(favicon.Config{
    37      File: "./favicon.ico",
    38      URL: "/favicon.ico",
    39  }))
    40  ```
    41  
    42  ## Config
    43  
    44  ```go
    45  // Config defines the config for middleware.
    46  type Config struct {
    47      // Next defines a function to skip this middleware when returned true.
    48      //
    49      // Optional. Default: nil
    50      Next func(c *fiber.Ctx) bool
    51  
    52      // File holds the path to an actual favicon that will be cached
    53      //
    54      // Optional. Default: ""
    55      File string
    56  	
    57      // URL for favicon handler
    58      //
    59      // Optional. Default: "/favicon.ico"
    60      URL string
    61  
    62      // FileSystem is an optional alternate filesystem to search for the favicon in.
    63      // An example of this could be an embedded or network filesystem
    64      //
    65      // Optional. Default: nil
    66      FileSystem http.FileSystem
    67  
    68      // CacheControl defines how the Cache-Control header in the response should be set
    69      //
    70      // Optional. Default: "public, max-age=31536000"
    71      CacheControl string
    72  }
    73  ```
    74  
    75  ## Default Config
    76  
    77  ```go
    78  var ConfigDefault = Config{
    79  	Next:         nil,
    80  	File:         "",
    81  	URL:          fPath,
    82  	CacheControl: "public, max-age=31536000",
    83  }
    84  ```