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

     1  ---
     2  id: etag
     3  title: ETag
     4  ---
     5  
     6  ETag middleware for [Fiber](https://github.com/gofiber/fiber) that lets caches be more efficient and save bandwidth, as a web server does not need to resend a full response if the content has not changed.
     7  
     8  ## Signatures
     9  
    10  ```go
    11  func New(config ...Config) fiber.Handler
    12  ```
    13  
    14  ## Examples
    15  
    16  Import the middleware package that is part of the Fiber web framework
    17  
    18  ```go
    19  import (
    20    "github.com/gofiber/fiber/v2"
    21    "github.com/gofiber/fiber/v2/middleware/etag"
    22  )
    23  ```
    24  
    25  After you initiate your Fiber app, you can use the following possibilities:
    26  
    27  ```go
    28  // Initialize default config
    29  app.Use(etag.New())
    30  
    31  // Get / receives Etag: "13-1831710635" in response header
    32  app.Get("/", func(c *fiber.Ctx) error {
    33      return c.SendString("Hello, World!")
    34  })
    35  
    36  // Or extend your config for customization
    37  app.Use(etag.New(etag.Config{
    38      Weak: true,
    39  }))
    40  
    41  // Get / receives Etag: "W/"13-1831710635" in response header
    42  app.Get("/", func(c *fiber.Ctx) error {
    43      return c.SendString("Hello, World!")
    44  })
    45  ```
    46  
    47  ## Config
    48  
    49  ```go
    50  // Config defines the config for middleware.
    51  type Config struct {
    52      // Next defines a function to skip this middleware when returned true.
    53      //
    54      // Optional. Default: nil
    55      Next func(c *fiber.Ctx) bool
    56  
    57      // Weak indicates that a weak validator is used. Weak etags are easy
    58      // to generate, but are far less useful for comparisons. Strong
    59      // validators are ideal for comparisons but can be very difficult
    60      // to generate efficiently. Weak ETag values of two representations
    61      // of the same resources might be semantically equivalent, but not
    62      // byte-for-byte identical. This means weak etags prevent caching
    63      // when byte range requests are used, but strong etags mean range
    64      // requests can still be cached.
    65      Weak bool
    66  }
    67  ```
    68  
    69  ## Default Config
    70  
    71  ```go
    72  var ConfigDefault = Config{
    73      Next: nil,
    74      Weak: false,
    75  }
    76  ```