繁体   English   中英

通过HTTP2请求更新存储的缓存

[英]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.cssmain.js时出现问题。 是否仅通过发送另一个/main.html请求来更新它们? 如果没有,我该如何更新它们?

不,他们不会更新。 当您尝试推送资产的新版本时,浏览器将重置流,因为它认为这些资产仍然是最新的。 并且它将继续使用旧版本的资产。

至少目前,解决方案是使用缓存摘要机制缓存清除。

在此处阅读详细信息:

https://www.shimmercat.com/en/info/articles/caching/

另请参阅此答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM