我正在使用 Google Chrome,注意到每次进行 XHR 请求时都会在请求上添加以下标头:
Cache-Control: no-cache
Pragma: no-cache
如果您阅读http://www.w3.org/TR/XMLHttpRequest/中的规范,它将说明以下内容:
如果用户代理实现了HTTP缓存,则应该遵守作者请求头中的Cache-Control头部(例如,Cache-Control:no-cache)以绕过缓存。除非最终用户明确要求此行为(例如通过重新加载页面),否则它不应自动发送Cache-Control或Pragma请求头。
我正在尝试以下操作:
$.ajax(myUrl, {
type: 'get',
dataType: 'json'
cache: true,
headers: {
'Cache-Control': 'max-age=200'
}
})
正如您所看到的,我明确设置了Cache-Control头,希望获得我的资源的缓存副本。然而,Chrome似乎忽略了Cache-Control头。
在发出XHR请求时,是否可能不发送Cache-Control: no-cache
头?