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

前端 未结 4 951
说谎
说谎 2021-02-07 11:05

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 r

相关标签:
4条回答
  • 2021-02-07 11:44

    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.

    0 讨论(0)
  • 2021-02-07 11:50
    app.disable('etag');
    

    preventing 'etag' in response may help

    0 讨论(0)
  • 2021-02-07 11:51

    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?

    0 讨论(0)
  • 2021-02-07 11:59

    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();    
    });
    
    0 讨论(0)
提交回复
热议问题