HTTP response freshness testing
This is a Node.js module available through the
npm registry. Installation is done using the
npm install command:
$ npm install fresh
var fresh = require('fresh')Check freshness of req and res headers.
When the cache is "fresh" true is returned, otherwise false is returned to indicate that the cache is now stale.
This module is designed to only following the HTTP specifications, not to work-around all kinda of client bugs (especially since this module typically does not recieve enough information to understand what the client actually is).
There is a known issue that in certain versions of Safari, Safari will incorrectly make a request that allows this module to validate freshness of the resource even when Safari does not have a representation of the resource in the cache. The module jumanji can be used in an Express application to work-around this issue and also provides links to further reading on this Safari bug.
var req = { 'if-none-match': 'tobi' };
var res = { 'etag': 'luna' };
fresh(req, res);
// => false
var req = { 'if-none-match': 'tobi' };
var res = { 'etag': 'tobi' };
fresh(req, res);
// => true