如何解决Google Page Speed:“未指定过期”

时间:2016-08-21 11:27:29

标签: nginx cache-control expires-header shopware

使用GooglePageSpeed分析在线商店(Shopware)会导致许多“未指定过期” - 每张图片上都有。

enter image description here

我很想知道因为网络服务器(nginx)将 Last-Modified -Timestamps和 ETAG 标头添加到所有图片的响应中,从而产生预期的304响应在第二个请求。

enter image description here

Google Page Speed不支持ETAG / LastModified吗?

我将提供nginx配置的相应部分:

location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
  expires 1M;
  access_log off;
  add_header Cache-Control "public";
}

## All static files will be served directly.
location ~* ^.+\.(?:css|cur|js|jpe?g|gif|ico|png|html|xml)$ {
    ## Defining rewrite rules
    rewrite files/documents/.* /engine last;
    rewrite backend/media/(.*) /media/$1 last;

    expires 1w;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";

    access_log off;
    # The directive enables or disables messages in error_log about files not found on disk.
    log_not_found off;

    tcp_nodelay off;
    ## Set the OS file cache.
    open_file_cache max=3000 inactive=120s;
    open_file_cache_valid 45s;
    open_file_cache_min_uses 2;
    open_file_cache_errors off;

    ## Fallback to shopware
    ## comment in if needed
    #try_files $uri @shopware;
}

是否有任何错误或缺失?

1 个答案:

答案 0 :(得分:1)

最后我们发现,vhost-config中还有另一个expire-statement。减少两个单一的声明解决了我们的问题