谷歌的网页抱怨woff没有被缓存

时间:2014-10-21 13:24:41

标签: nginx pagespeed google-pagespeed

我目前正在优化nginx pagespeed(ngx_pagespeed)的配置,而且pagespeed一直在抱怨缺少缓存woff文件。

这就是我的配置:

server {
    location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
    location ~ "^/ngx_pagespeed_static/" { }
    location ~ "^/ngx_pagespeed_beacon" { }
    location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
    location /ngx_pagespeed_global_statistics { allow 127.0.0.1; deny all; }
    location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }
    location /pagespeed_console { allow 127.0.0.1; deny all; }

    pagespeed EnableFilters extend_cache;
    pagespeed EnableFilters inline_google_font_css;

    access_log      /var/www/servers/mysite/production/logs/nginx_access.log;
    error_log       /var/www/servers/mysite/production/logs/nginx_error.log;
    listen          80;
    server_name     mysite.com;
    charset         utf-8;

    client_max_body_size    75M;

    location / {
        uwsgi_pass  unix:/var/www/servers/mysite/production/sockets/mysite.sock;
        include     /var/www/servers/mysite/production/configs/uwsgi/uwsgi_params_pro;
    }

    location /static {
        autoindex   on;
        alias       /var/www/servers/mysite/production/static;
    }

    location /media {
        autoindex   on;
        alias       /var/www/servers/mysite/production/media;
    }
}

我是否需要为包含/static文件的woff库定义更多参数?

更新

我更改了我的静态位置,以检测我是否需要Cache-Control的特定文件,然后添加如下参数:

location /static {
    autoindex   off;
    alias       /var/www/servers/mysite/production/static;

    if ($request_filename ~* ^.*?\.(eot)|(ttf)|(woff)|(svg)|(otf)$){
       expires 1y;
       add_header Cache-Control public;
    } 
}

1 个答案:

答案 0 :(得分:0)

ngx_pagespeed目前不支持延长woff文件的缓存生命周期。您可以告诉Nginx使用长TTL提供woff文件,或者从ngx_ / mod_pagespeed请求此功能。