IE重复请求的快速返回304 [英] express returns 304 for IE repeative requests

查看:222
本文介绍了IE重复请求的快速返回304的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了ExpressJS的一些奇怪行为.在对基于node.js/express的API URL的第二次请求时,它总是向IE返回304 Not Modified响应代码.其他浏览器获得200(Chrome/FF).问题是,即使实际上已经更改了内容,它也会返回304.我尝试搜索,但找不到关于该主题的任何内容.另外,我尝试在IE和Chrome的请求标头中查找差异,并且可以看到可能导致此标头的任何标头.任何帮助将不胜感激.

I'm experiencing some strange behavior of ExpressJS. On second request to my node.js/express based API URL it always returns 304 Not Modified response code to IE. Other browsers get 200(Chrome/FF). The problem is, that it returns 304 even if the content actually has been changed. I tried to search, and couldn't find anything on the topic. Also I tried to find a difference in requests headers of IE and Chrome, and could see any header that may cause that. Any help will be appreciated.

如果需要的话,我必须添加通过SSL的连接

I have to add the connection goes via SSL, in case it matters

推荐答案

Cache-Control标头是一种解决方法.该错误在于Internet Explorer对标头的HTTP 1.1规范的解释.

The Cache-Control header is a workaround. The bug is in internet explorer's interpretation of the HTTP 1.1 spec for the header.

我将此添加到了路由处理程序中,从而解决了该问题.您还需要一个Last-ModifiedETag标头,但是express已经为我发送了该标头.

I added this to my route handler, which solved the problem. You also need a Last-Modified or ETag header, but express was already sending that for me.

res.setHeader("Expires", "-1");
res.setHeader("Cache-Control", "must-revalidate, private");

请参阅:使IE缓存资源,但总是重新验证

这篇关于IE重复请求的快速返回304的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆