Chrome浏览器缓存HTTP PUT请求 [英] Chrome is caching an HTTP PUT request

查看:1725
本文介绍了Chrome浏览器缓存HTTP PUT请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有镀铬这个奇特的问题。它经常出现缓存PUT请求。

的详细信息:我在使用Backbone.js的一个应用程序,并试图在坚持一些修改模型(骨干会自动生成一个PUT请求),铬只是不会将请求发送到服务器。它工作在Firefox和IE完美的罚款(还没有看到这个问题在Safari至今)。

下面是从Chrome开发者工具网络选项卡的屏幕截图。正如你所看到的,对于PUT请求的响应是从缓存(请求不打服务器!!)返回

下面是相同的请求的头信息截图。再次,很明显,Chrome不打扰发送PUT请求给服务器。

请求的有效载荷是JSON数据。任何想法,为什么发生这种情况/我在做什么错了?

更新:铬已经确认这确实是一个的上的错误结束(感谢扬Hančič)。

临时解决方案
我结束了覆盖 Backbone.sync 方法和附加一个时间戳PUT,POST的查询字符串和DELETE请求,让他们始终是唯一的:

 如果(options.data&安培;!&放大器;模型和放大器;及(方法=='创造'||方法=='更新'||方法=='删除' )){
    params.url + =(params.url.indexOf()== -1'?'?'?':'和;')+'_ ='+新的Date()的getTime();
}


解决方案

我用额外的参数,以避免缓存:

  URL + = +的Math.random()toFixed(20).replace('''')'_dc =?。

我不跨preT这个参数在服务器端。

编辑:铬此外,还有很多事情可以缓存请求 - 例如用户的代理服务器。我认为,额外的查询参数是一个很好的解决方案,保持了高速缓存。

I have this bizarre issue with Chrome. It quite often appears to cache PUT requests.

The Details: I have an app using backbone.js and when trying to persist some changes to a model (backbone automatically generates a PUT request), Chrome just wont send that request to the server. It works perfectly fine in Firefox and IE (haven't seen the issue in Safari so far).

Here's a screenshot from the Chrome developer tools' Network tab. As you can see, the response for the PUT request is being returned from cache (the request doesn't hit the server!!)

Here's a screenshot of the header details of that same request. Once again, it's evident that Chrome doesn't bother sending the PUT request to the server.

The payload of the request is JSON data. Any thoughts as to why this is happening / what I'm doing wrong?

UPDATE: Chromium has confirmed that this is indeed a bug on it's end (thanks Jan Hančič).

TEMPORARY SOLUTION I ended up overriding Backbone.sync method and appending a timestamp to the querystring of PUT, POST and DELETE requests so that they are always unique:

if(!options.data && model && (method == 'create' || method == 'update' || method == 'delete')) {
    params.url += (params.url.indexOf('?') == -1 ? '?' : '&') + '_=' + new Date().getTime();
}

解决方案

I use extra parameter to avoid caching:

url += '?_dc=' + Math.random().toFixed(20).replace('.', '');

I don't interpret this parameter on server side.

EDIT: Besides of chrome there are a lot things could cache requests - user's proxy server for instance. I think additional query parameter is a good solution to keep out of caching.

这篇关于Chrome浏览器缓存HTTP PUT请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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