Socket
Socket
Sign inDemoInstall

nocache

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    nocache

Middleware to destroy caching


Version published
Weekly downloads
2.3M
increased by1.21%
Maintainers
1
Install size
3.06 kB
Created
Weekly downloads
 

Package description

What is nocache?

The nocache package is a middleware for Node.js applications that sets headers to disable client-side caching. This is particularly useful for ensuring that sensitive or frequently updated content is not stored in the user's cache, thereby enforcing content freshness and enhancing security.

What are nocache's main functionalities?

Disabling Caching

This code demonstrates how to use the nocache middleware in an Express application to disable client-side caching for all routes. By calling `app.use(nocache());`, all responses from the server will include headers that instruct the browser not to cache the content.

const express = require('express');
const nocache = require('nocache');

const app = express();

app.use(nocache());

app.get('/', (req, res) => {
  res.send('Hello, World!');
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

Other packages similar to nocache

Changelog

Source

4.0.0 - 2023-06-01

Removed

  • Breaking: dropped Pragma header. See #26
  • Breaking: dropped support for Node 14 and 15. Node 16+ is now required

Readme

Source

Middleware to turn off caching

This Express middleware sets some HTTP response headers to try to disable client-side caching.

To use it:

const nocache = require("nocache");

// ...

app.use(nocache());

This sets three headers, disabling a lot of browser caching:

  • Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate
  • Expires: 0
  • Surrogate-Control: no-store

You may wish to do this if you want to ensure that users have up-to-date resources, or if you want to clear out an old version for some reason.

Keywords

FAQs

Last updated on 01 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc