简体   繁体   English

HTTP缓存-设置“缓存控制标头”后,资产不从浏览器缓存中提供

[英]HTTP Caching - Asset not serving from browser cache after setting Cache-Control Header

Initial Request 初始请求 初始请求 Second Request 第二个请求 第二个请求 I am using a node module(express-cache-ctrl) to enable caching on aa proxy . 我正在使用节点模块(express-cache-ctrl)启用对proxy的缓存。

app.use(cache.public(3600));

My static assets have a Cache-control header on them with max-age . 我的静态资产上带有max-age的Cache-control标头。 I am unable to figure out why they reload on a refresh and not served from browser-cache . 我无法弄清楚为什么它们会在刷新时重新加载,而不是从browser-cache服务。

Edit : ` 编辑:

var onProxyRes = function(proxyRes, req, res) {
    if ( proxyRes.headers["content-type"] == "text/css" || 
    proxyRes.headers["content-type"] == "application/javascript") {
    proxyRes.headers["Cache-Control"] = "public, max-age=86400";
  }

//add something here to modify proxy response };` Tried manually adding caching header on proxy response also doesn't cache assets //在此处添加一些内容以修改代理响应};`尝试在代理响应上手动添加缓存标头也不会缓存资产

Found this in a Chrome forum , while running a https server if you have any kind of SSL error then in that case browser prevents caching over HTTPS https://bugs.chromium.org/p/chromium/issues/detail?id=110649 . 如果您遇到任何SSL错误,则在Chrome论坛中运行https服务器时会在Chrome论坛中找到此问题,在这种情况下,浏览器会阻止通过HTTPS https://bugs.chromium.org/p/chromium/issues/detail?id=110649进行缓存。 。 Works for me now 现在为我工作

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

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