Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Hold on, we're currently generating a fresh version of this report
Generated on May 15, 2024 via pnpm

fresh 0.5.2

HTTP response freshness testing
Package summary
Share
0
issues
1
license
1
MIT
Package created
10 Jun 2012
Version published
14 Sep 2017
Maintainers
1
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
fresh@0.5.2
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of fresh 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does fresh do?

The Fresh package is a Node.js module that helps with HTTP response freshness testing. It checks the freshness of a response using client and server headers. If the client's cache still possesses a fresh version of the resource, the module returns true. On the contrary, if the client's cache is stale, it returns false, indicating that a full response should be sent again. The Fresh module adheres strictly to HTTP specifications and doesn't aim to resolve all client bugs. However, for certain known issues, such as Safari-related caching problems, reference to another module like jumanji is suggested.

How do you use fresh?

After installing the npm module fresh with the command npm install fresh, it can be implemented into your JS project with the following syntax:

const fresh = require('fresh')

let reqHeaders = { 'if-none-match': '"foo"' }
let resHeaders = { 'etag': '"bar"' }
console.log(fresh(reqHeaders, resHeaders)) // Output: false

reqHeaders = { 'if-none-match': '"foo"' }
resHeaders = { 'etag': '"foo"' }
console.log(fresh(reqHeaders, resHeaders)) // Output: true

In the above example, fresh is checking the request and response headers' freshness. If the headers match, it returns true, implying that the client still contains a fresh version of the resource, else it returns false.

For implementation with Node.js HTTP server:

const fresh = require('fresh')
const http = require('http')

const server = http.createServer((req, res) => {
  /* perform server logic, including adding ETag / Last-Modified response headers */

  if (isFresh(req, res)) {
    // if client has a fresh copy of the resource
    res.statusCode = 304
    res.end()
    return
  }
  
  // Else, send the resource
  res.statusCode = 200
  res.end('hello, world!')
})

const isFresh = (req, res) => {
  return fresh(req.headers, {
    'etag': res.getHeader('ETag'),
    'last-modified': res.getHeader('Last-Modified')
  })
}

server.listen(3000)

The example shows the integration of the fresh module with a Node.js HTTP server. The function isFresh checks the request and response headers to verify if the client's cache contains a fresh copy of the resource or not.

Where are the fresh docs?

The Fresh module documentation can be found within its npm registry. The README file provides comprehensive coverage of its functionality, known issues, and examples of how to use it. The fresh module follows the HTTP standards strictly and checks the freshness of the HTTP response based on the request and response headers. This information ensures optimal design and implementation of server-client communication by adhering to best practices for resource freshness, cache control, and HTTP response handling.