npm install @ferrow/etag-generatorETag generation and If-None-Match comparison for HTTP caching per RFC 7232.
import { strongETag, decide } from "etag-generator";
const content = "page content";
const etag = strongETag(content);
const result = decide(req.headers, etag);
// → { status: 304, headers: { ETag: "..." } } if cachedGenerate strong ETag from content (SHA256, first 27 base64url chars).
Generate weak ETag from file size and mtime (for file-based caching).
Check If-None-Match header against ETag (handles W/ prefix and * wildcard per RFC 7232).
Evaluate conditional request headers; returns 304 if matched, 200 with caching headers otherwise.
Async helper to generate weak ETag from file stats.
- Strong ETags use SHA256 first 27 base64url chars (not full hash)
- Weak ETags can change despite identical content (mtime-based)
- No Last-Modified evaluation
Part of the ferrow-toolkit collection · Sponsored by Ferrow