[英]Update cache stored via HTTP2 requests
通常,我會通過http2請求提供文件,如下所示:
if (req.url === '/main.html') {
let files = {
'main.css': {
type: 'text/css'
},
'main.js': {
type: 'application/javascript'
}
};
for (let name in files) {
let push = res.push('/' + name, {
response: {
'Content-Type': files[name].type,
'Cache-Control': 'public, max-age=31556926'
}
});
push.on('error', er => console.log(er));
push.end(fs.readFileSync('/home/src/' + name));
}
res.writeHead(200, {
'Content-Type': 'text/html'
});
res.end(`
<html>
<head>
<link rel="stylesheet" href="/main.css">
<script src="/main.js"></script>
</head>
<body></body>
</html>
`);
}
當有新內容可用時,更新這兩個文件main.css
和main.js
時出現問題。 是否僅通過發送另一個/main.html
請求來更新它們? 如果沒有,我該如何更新它們?
不,他們不會更新。 當您嘗試推送資產的新版本時,瀏覽器將重置流,因為它認為這些資產仍然是最新的。 並且它將繼續使用舊版本的資產。
至少目前,解決方案是使用緩存摘要機制和緩存清除。
在此處閱讀詳細信息:
https://www.shimmercat.com/en/info/articles/caching/
另請參閱此答案 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.