【问题标题】:Leverage Browser Caching in PageSpeed Insights with Varnish & Nginx使用 Varnish 和 Nginx 在 PageSpeed Insights 中利用浏览器缓存
【发布时间】:2016-12-01 23:28:09
【问题描述】:

有谁知道如何使用 Varnish Cache 和 Nginx 从 PageSpeed Insights 中删除 Leverage Browser Caching 消息?

Google PageSpeed Image

我已尝试将位置 ~*... 块添加到服务器块,但这会使网站崩溃。我想我错过了清漆设置,但找不到。

提前致谢!

【问题讨论】:

    标签: caching nginx


    【解决方案1】:

    要覆盖这些标头并仍然将元素放入缓存中 2 分钟,可以使用以下配置:

    sub vcl_fetch {
      if (beresp.ttl < 120s) {
       set beresp.ttl = 120s;
    
       # Set the clients TTL on this object
       set beresp.http.Cache-Control = "max-age=120";
      }
    }
    

    或者,在 Varnish 4.0 中:

    sub vcl_backend_response {
      if (beresp.ttl < 120s) {
        set beresp.ttl = 120s;
        unset beresp.http.Cache-Control;
        set beresp.http.Cache-Control = "max-age=120";
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-23
      • 1970-01-01
      • 2014-12-04
      • 1970-01-01
      • 2014-07-08
      • 2017-08-19
      相关资源
      最近更新 更多