The `fresh` package (version 0.5.2, last published in September 2017) is a minimalist Node.js utility designed to determine if an HTTP response is "fresh" according to client-provided caching headers. Part of the `jshttp` organization, which maintains foundational HTTP middleware and utilities leveraged by frameworks such as Express.js, this library compares a client's `If-None-Match` and `If-Modified-Since` request headers against a server's `ETag` and `Last-Modified` response headers. It returns `true` if the cached response is still valid, indicating a conditional GET request can result in a 304 Not Modified status, or `false` if the cache is stale and a full response is required. Its primary differentiators are strict adherence to HTTP specifications and a focused scope, prioritizing reliability for efficient conditional GET implementations. Given its mature and foundational nature, the package maintains a stable, maintenance-level release cadence with infrequent updates.
npm install freshVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use the `fresh` function with example request and response headers to check HTTP cache freshness.
For applications requiring workarounds for specific client caching behaviors, consider augmenting `fresh` with additional logic or middleware like `jumanji` (for Express) to handle known browser inconsistencies.
Use `const fresh = require('fresh');` for strict CommonJS environments. For native ESM environments, rely on bundler transpilation, or use dynamic `import('fresh').then(m => m.default)` if direct ESM loading is required and the package's `package.json` does not include `exports`.Use a default import for ESM (`import fresh from 'fresh'`) or directly assign the result of `require()` for CommonJS (`const fresh = require('fresh')`).Ensure request and response header keys are consistently lowercase or normalized before passing them to `fresh`, or rely on the module's internal parsing to handle standard HTTP header casing. Always provide full HTTP-standard header strings (e.g., `Last-Modified` in RFC1123 format).
No dependency data recorded yet.