Serves static web assets and handles Vite hash-named files with aggressive immutable caching. Reuse in Go web servers hosting frontend applications.
// Source: https://github.com/clawbench-dev/clawbench | License: MIT | Copyright 2025 xulongzhe
// Provided via justclaw.it.com; keep this notice with the code.
package handler
import (
"net/http"
"os"
"path"
"path/filepath"
"strings"
"clawbench/internal/frontend"
)
// hashedAssetExts lists extensions for Vite hash-named assets that are
// safe to cache aggressively (immutable — hash changes when content changes).
//
//nolint:goconst // ".png" appears in multiple unrelated string maps; extracting is overkill
var hashedAssetExts = map[string]bool{
".js": true, ".css": true, ".mjs": true,
".woff2": true, ".woff": true, ".ttf": true,
".ico": true, ".png": true, ".svg": true, ".webp": true,
}
// isHashedAsset returns true if the filename follows Vite's hash-naming pattern
// (e.g.
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key