This is a really strange mistake that has bothered me for ages. I have a basic website that uses Express Static middleware in addition to the individual routes that Jade displays.
Here is my configuration
app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(stylus.middleware({ src : __dirname + '/public', dest : __dirname + '/public', compile : function(str, path) { return stylus(str) .set('filename', path) .set('compress', true) .use(nib()) } })); app.use(bodyParser.urlencoded({ extended: false })) app.use(bodyParser.json()) app.use(cookieParser()) app.use(session({ secret: conf.sessionSecret, store: new RedisStore(), saveUninitialized: true, resave: true })); app.use(express.static(__dirname + '/public'))
Here is my problem. After 5 updates on one tab in Chrome, image files refuse to download. All other content is fine, just images and only in Chrome. To fix this, you need to open a new tab. I also tested this in Firefox - no problem. This error does not just happen in this application - it happened in many of my others.
Since this project is currently under development, I would prefer not to bring it online as an example. Be sure this is fully reproducible. Any ideas?
UPDATE: I upgraded to Express 4 with a slight chance that an update could fix my problem. This is not true. You can see the screen I made from here .
UPDATE: to check if there was a problem with the static server, I changed my code like this:
app.get('/img/*', function (req,res) { console.log(req.url); console.log(path.extname(req.url)); if (imgExt.indexOf(path.extname(req.url)) != -1) { res.sendfile('./public/'+req.url); } }); app.use(express.static(__dirname + '/public'))
This had no effect, so I think this problem is either a client or a bug with Chrome.