【问题标题】:Google pagespeed complaining about woff not being cached谷歌 pagespeed 抱怨 woff 没有被缓存
【发布时间】:2014-10-23 05:23:16
【问题描述】:

我目前正在优化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;
    }
}

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

更新

我更改了我的静态位置以检测它是否是我想要缓存控制的特定文件,然后添加如下参数:

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;
    } 
}

【问题讨论】:

    标签: nginx pagespeed google-pagespeed


    【解决方案1】:

    ngx_pagespeed 目前不支持延长 woff 文件的缓存寿命。你可以告诉 Nginx 提供具有长 TTL 的 woff 文件,或者向 ngx_/mod_pagespeed 请求此功能。

    【讨论】:

    • 如何将long TTL 与我当前的设置混合使用?
    • 我不是很了解nginx,但是location ~* \.woff$ { expires 1y; }应该可以。
    猜你喜欢
    • 2012-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-18
    • 2018-11-18
    • 2018-06-20
    • 2011-05-11
    相关资源
    最近更新 更多