[Node.js] 学习笔记 - express router

参考:
http://stackoverflow.com/questions/12695591/node-js-express-js-how-does-app-router-work

The best option is to put all of your static resources under a specific folder. (IE /static) You can then mount static to that path so that it only runs when the path starts with /static:

app.use('/static', express.static(__dirname + '/static'));


In this situation, you'd put this above router. This avoids processing other middleware/the router if a file is present, but to be honest, I doubt you'll gain that much.

You could also use staticCache, which caches static resources in-memory so that you don't have to hit the disk for commonly requested files. (Warning: staticCache will apparently be removed in the future.)

However, I don't think staticCache caches negative answers (when a file does not exist), so it doesn't help if you've put staticCache above router without mounting it to a path.

猜你喜欢

转载自cute-spring.iteye.com/blog/2050149