express ajax 304缓存禁用,node.js - NodeJS/express: Cache and 304 status code - Stack Overflow

When I reload a website made with express, I get a blank page with Safari (not with Chrome) because the NodeJS server sends me a 304 status code.

How to solve this?

Of course, this could also be just a problem of Safari, but actually it works on all other websites fine, so it has to be a problem on my NodeJS server, too.

To generate the pages, I'm using Jade with res.render.

Update: It seems like this problem occurs because Safari sends 'cache-control': 'max-age=0' on reload.

Update 2: I now have a workaround, but is there a better solution?

Workaround:

app.get('/:language(' + content.languageSelector + ')/:page', function (req, res)

{

// Disable caching for content files

res.header("Cache-Control", "no-cache, no-store, must-revalidate");

res.header("Pragma", "no-cache");

res.header("Expires", 0);

// rendering stuff here…

}

Update 3:

So the complete code part is currently:

app.get('/:language(' + content.languageSelector + ')/:page', pageHandle);

function pageHandle (req, res)

{

var language = req.params.language;

var thisPage = content.getPage(req.params.page, language);

if (thisPage)

{

// Disable caching for content files

res.header("Cache-Control", "no-cache, no-store, must-revalidate");

res.header("Pragma", "no-cache");

res.header("Expires", 0);

res.render(thisPage.file + '_' + language, {

thisPage : thisPage,

language: language,

languages: content.languages,

navigation: content.navigation,

footerNavigation: content.footerNavigation,

currentYear: new Date().getFullYear()

});

}

else

{

error404Handling(req, res);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值