我正在创建一个动态 node.js 网站。我不希望浏览器存储页面,即每当用户单击重新加载时,我希望页面从头开始重新加载。目前,即使我发送“Cache-Control”:“no store”,我的页面似乎仍然被缓存。这是我的服务器:
// requires node's http module
var http=require('http');
var url=require('url');
var fs=require('fs');
// creates a new httpServer instance
http.createServer(function (req, res) {
// this is the callback, or request handler for the httpServer
log('in server callback')
res.ins=res.write;
var parse=url.parse(req.url,true);
var path0=parse.pathname;
var mime=core.getMime(path0)
console.log(path0)
// respond to the browser, write some headers so the
// browser knows what type of content we are sending
var servePage=function(){
var path='./page'+path0+'.js'
console.log(path)
fs.exists(path,function(e){
if(e){
log('serving page')
var exp=require(path);
if(exp && exp.html){
var html=exp.html
}
else{
var html='bad file'
}
}
else{
console.log('no page to serve')
var exp=require('./page/pageHome.js')
var html=exp.html
}
res.writeHead(200, {'Content-Type': mime, 'Cache-Control': 'no store'});
res.ins(html);
res.end();
})
}
servePage()
}).listen(8080); // the server will listen on port 8080
我还尝试使用诸如“ http://mydomain.com/page?q=42 ”之类的随机查询字符串创建自链接,但这仍然没有绕过缓存。我究竟做错了什么?谢谢!