简体   繁体   中英

Express doesn't return 304 for static json

I'm using express.static to serve a very large, static json file. While express.static will return 304 when other static resources are unchanged, it always returns 200 for static json.

Because of the size of the file and the nature of my application, I want to avoid clients downloading the file unless it has changed.

How can I convince express to return 304 for my json?

您可以在返回中强制使用状态代码:

res.status(304).json({ data: 'data' }); // or 200

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM