admin管理员组文章数量:1402902
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 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();
}
Share
Improve this question
edited Aug 1, 2012 at 21:58
anushr
asked Aug 1, 2012 at 6:33
anushranushr
3,4003 gold badges31 silver badges50 bronze badges
6
- 2 Does this only happen if you send data in the PUT request, that you'll already send before or does this also occure if you change the data to be submitted and trigger the request again? – Robin Drexler Commented Aug 1, 2012 at 6:45
- The response from the server doesn't change maybe that's why its cached. Like Robin said, change/correct the request – Zebra Commented Aug 1, 2012 at 6:46
- 1 The data definitely changes. However, I would think that it shouldn't matter whether the data has changed or not. A PUT really isn't a cacheable request type. It's meant to send data to the server, not fetch data. – anushr Commented Aug 1, 2012 at 6:48
- 3 This is probably related to this bug: code.google./p/chromium/issues/… – Jan Hančič Commented Aug 1, 2012 at 7:20
- Nasty, I think this is specifically related to xhr, which implemented today will aggressively use the cache (not even issuing 304 expectant requests) – meandmycode Commented Aug 1, 2012 at 7:33
2 Answers
Reset to default 4I 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.
Backbone use jQuery or Zepto to make the AJAX request. Assuming that you are using jQuery, set the cache off.
Run this to set the cache off in the overall application so you will not need to worry about cache:
$.ajaxSetup({
cache : false
});
If keep the cache on is important for your business, I think that you could do something like this for specific no cache calls:
model.save({}, {cache:false});
本文标签: javascriptChrome is caching an HTTP PUT requestStack Overflow
版权声明:本文标题:javascript - Chrome is caching an HTTP PUT request - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744354710a2602247.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论