谷歌浏览器怎么重发请求_Chrome浏览器缓存HTTP PUT请求

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值