Favicon middleware for Fiber that caches and serves favicon requests, reducing disk I/O and preventing noisy logs. Mount it before your logger middleware to suppress repeatedDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/gofiber/fiber/llms.txt
Use this file to discover all available pages before exploring further.
/favicon.ico requests.
Installation
Signatures
Usage
Basic Usage
Custom Configuration
Using Embedded Filesystem
Configuration
Function to skip this middleware when it returns true.
Raw data of the favicon file. Use this instead of
File to serve favicon from memory.Path to the favicon file that will be cached. Can be a local file path or embedded filesystem path. Default: empty string.
URL path where the favicon handler will be mounted. Default:
/favicon.ico.Optional alternate filesystem to load the favicon from (e.g.,
os.DirFS or embed.FS).Value for the Cache-Control header in the response. Default:
public, max-age=31536000 (1 year).Maximum size limit for the cached favicon asset in bytes (default is 1MB).
Default Configuration
Best Practices
- Mount the favicon middleware before the logger middleware to avoid noisy logs
- Use the
Datafield for small favicons to avoid disk I/O entirely - Set appropriate
CacheControlheaders to reduce server load - For multiple icon sizes, use the Static middleware instead
- The middleware only handles GET, HEAD, and OPTIONS methods
Common Patterns
Suppress Favicon Logs
Serve Multiple Icon Formats
The favicon middleware only serves a single icon. For multiple formats (png, svg, etc.), use the Static middleware:Development vs Production
Custom URL Path
Notes
- The middleware only handles requests to the configured URL path (default:
/favicon.ico) - Requests with unsupported methods return
405 Method Not Allowed - The favicon is loaded once on startup and cached in memory
- If the file size exceeds
MaxBytes, the middleware will return an error