admin管理员组文章数量:1326060
I'm making requests to JSON objects with node using http.get(), it all works fine but, in some cases, I get an outdated version of the page (there's a date field that enables me to make sure). The behaviour is really inconsistent, I can get the right thing one moment, and the wrong thing the next... Here's my request :
var options = {host:'host',path:urlPath,headers:{'Cache-Control':'no-cache'}}
http.get(options, function(res){
//JSON.parse result and check the date, sometimes 17/1, sometimes 10/1
});
Is there anything wrong with the request header? I tried 'max-age=0' instead of 'no-cache', to no avail..., does anyone have an idea where this could e from? In my browser, I get the last version all the time, a bit lost here, Help!
I'm making requests to JSON objects with node using http.get(), it all works fine but, in some cases, I get an outdated version of the page (there's a date field that enables me to make sure). The behaviour is really inconsistent, I can get the right thing one moment, and the wrong thing the next... Here's my request :
var options = {host:'host.',path:urlPath,headers:{'Cache-Control':'no-cache'}}
http.get(options, function(res){
//JSON.parse result and check the date, sometimes 17/1, sometimes 10/1
});
Is there anything wrong with the request header? I tried 'max-age=0' instead of 'no-cache', to no avail..., does anyone have an idea where this could e from? In my browser, I get the last version all the time, a bit lost here, Help!
Share Improve this question asked Jan 16, 2014 at 22:24 xShirasexShirase 12.4k4 gold badges54 silver badges86 bronze badges 1-
2
Have you tried appending a random string at the end? E.g.
'host.'+(new Date().valueOf())
– MMM Commented Jan 16, 2014 at 22:49
1 Answer
Reset to default 6Solved it, thanks to users ment, what I did is :
urlPath+="&ie="+(new Date()).getTime();
var options = {host:'host.',path:urlPath,headers:{'Cache-Control':'no-cache'}}
http.get(options, function(res){
//JSON.parse result and check the date, sometimes 17/1, sometimes 10/1
});
Stupid and awesome at the same time...
本文标签: javascriptCacheControl in nodejs httpgetStack Overflow
版权声明:本文标题:javascript - Cache-Control in node.js http.get - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742197617a2431369.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论