Socket
Socket
Sign inDemoInstall

nocache

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nocache - npm Package Compare versions

Comparing version 0.4.0 to 1.0.0

24

index.js

@@ -1,16 +0,14 @@

module.exports = function nocache(options) {
module.exports = function nocache (options) {
var noEtag = (options || {}).noEtag
var noEtag = (options || {}).noEtag;
return function nocache(req, res, next) {
res.setHeader('Surrogate-Control', 'no-store');
res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
res.setHeader('Pragma', 'no-cache');
res.setHeader('Expires', '0');
return function nocache (req, res, next) {
res.setHeader('Surrogate-Control', 'no-store')
res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate')
res.setHeader('Pragma', 'no-cache')
res.setHeader('Expires', '0')
if (noEtag) {
res.removeHeader('ETag');
res.removeHeader('ETag')
}
next();
};
};
next()
}
}

@@ -8,3 +8,4 @@ {

"description": "Middleware to destroy caching",
"version": "0.4.0",
"version": "1.0.0",
"license": "MIT",
"keywords": [

@@ -25,9 +26,16 @@ "helmet",

"scripts": {
"test": "mocha"
"test": "standard && mocha"
},
"devDependencies": {
"connect": "^3.3.1",
"mocha": "^2.0.1",
"supertest": "^0.15.0"
"connect": "^3.4.0",
"mocha": "^2.3.4",
"standard": "^5.4.1",
"supertest": "^1.1.0"
},
"standard": {
"globals": [
"describe",
"it"
]
}
}

@@ -1,4 +0,5 @@

# Middleware to turn off caching
Middleware to turn off caching
==============================
[![Build Status](https://travis-ci.org/helmetjs/nocache.svg?branch=master)](https://travis-ci.org/helmetjs/nocache)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)

@@ -8,14 +9,19 @@ It's possible that you've got bugs in an old HTML or JavaScript file, and with a cache, some users will be stuck with those old versions. This will (try to) abolish all client-side caching.

```javascript
var nocache = require('nocache');
app.use(nocache());
var nocache = require('nocache')
app.use(nocache())
```
This will set `Cache-Control` and `Pragma` headers to stop caching. It will also set an `Expires` header of 0, effectively saying "this has already expired."
This sets four headers, disabling a lot of browser caching:
- `Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate`
- `Pragma: no-cache`
- `Expires: 0`
- `Surrogate-Control: no-store`
If you want to crush the `ETag` header as well, you can:
```javascript
app.use(nocache({ noEtag: true }));
app.use(nocache({ noEtag: true }))
```
Caching has some real benefits, and you lose them here. Browsers won't cache resources with this enabled, although *some* performance is retained if you keep ETag support. It's also possible that you'll introduce *new* bugs and you'll wish people had old resources cached, but that's less likely.
Caching has some real benefits, and you lose many of them here. Browsers won't cache resources with this enabled, although *some* performance is retained if you keep ETag support. It's also possible that you'll introduce *new* bugs and you'll wish people had old resources cached, but that's less likely.

@@ -1,55 +0,56 @@

var nocache = require('..');
var nocache = require('..')
var assert = require('assert');
var connect = require('connect');
var request = require('supertest');
var assert = require('assert')
var connect = require('connect')
var request = require('supertest')
function helloWorld(req, res) {
res.end('Hello world!');
}
describe('nocache', function () {
it('sets headers properly', function (done) {
var app = connect()
app.use(function (req, res, next) {
res.setHeader('ETag', 'abc123')
next()
})
app.use(nocache())
app.use(function (req, res) {
res.end('Hello world!')
})
var app;
beforeEach(function () {
app = connect();
app.use(nocache());
app.use(helloWorld);
});
it('sets headers properly', function (done) {
request(app).get('/')
.expect('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate')
.expect('Pragma', 'no-cache')
.expect('Expires', '0')
.end(done);
});
.expect('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate')
.expect('Pragma', 'no-cache')
.expect('Expires', '0')
.expect('ETag', 'abc123')
.end(done)
})
it('can be told to squash etags', function (done) {
app = connect();
app.use(function(req, res, next) {
res.setHeader('ETag', 'abc123');
next();
});
app.use(nocache({ noEtag: true }));
app.use(helloWorld);
var app = connect()
app.use(function (req, res, next) {
res.setHeader('ETag', 'abc123')
next()
})
app.use(nocache({ noEtag: true }))
app.use(function (req, res) {
res.end('Hello world!')
})
request(app).get('/')
.expect('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate')
.expect('Pragma', 'no-cache')
.expect('Expires', '0')
.end(function (err, res) {
if (err) {
done(err);
return;
}
assert.equal(res.header.etag, undefined);
done();
});
});
.expect('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate')
.expect('Pragma', 'no-cache')
.expect('Expires', '0')
.end(function (err, res) {
if (err) {
done(err)
return
}
assert.equal(res.header.etag, undefined)
done()
})
})
it('names its function and middleware', function () {
assert.equal(nocache.name, 'nocache');
assert.equal(nocache().name, 'nocache');
});
});
assert.equal(nocache.name, 'nocache')
assert.equal(nocache().name, 'nocache')
})
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc