How to totally prevent HTTP 304 responses in Connect/Express static middleware?

。_饼干妹妹 提交于 2019-12-03 16:16:43

问题


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 }))

回答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();    
});



回答2:


app.disable('etag');

preventing 'etag' in response may help




回答3:


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?




回答4:


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.



来源:https://stackoverflow.com/questions/14641308/how-to-totally-prevent-http-304-responses-in-connect-express-static-middleware

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!