At times during development, it would be really nice to prevent HTTP 304 responses (in favor of 200's), and cause the Connect/Express static middleware to read every response from the filesystem, rather than do any caching at all.

I have tried playing with maxAge values of 0 and 1, to no avail:

app.use(express.static(__dirname + '/public', { maxAge: 1 }))
有帮助吗?

解决方案

I get 200 responses by doing this during development :

var express = require('express');
app = express();
app.use(function(req, res, next) {
  req.headers['if-none-match'] = 'no-match-for-this';
  next();    
});

其他提示

app.disable('etag');

preventing 'etag' in response may help

it does read from the file system on every response. it's just that if the request ETAG matches the response ETAG, it doesn't send the body of the response because it doesn't have to . It's the same file with the same hash. this is how 304 responses work.

why do you want to prevent 304 responses?

This solution is just a workaround. You could solve the problem from the browser side by disabling caching in Chrome. This doesn't help you if you need to work on something outside of Chrome, like Safari on iOS.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top