如图所示请求中带有If-None-Match和If-Modified-Since头,响应中也含有Etag和Last-Modified头,并且etag相等,Last-Modified也符合。理论上应该返回304 Not Modified吧。可是我试了好几次,每次都是200ok,没有利用缓存。服务端用的是koa和koa-etag中间件。该怎么办呢?
1 回答

ibeautiful
TA贡献1993条经验 获得超5个赞
app.use(async (ctx, next) => {
await next();
if (ctx.fresh) {
ctx.status = 304;
}
});
通过ctx.fresh来判断是否过期,没有则设置响应为304。
添加回答
举报
0/150
提交
取消