I am currently optimizing the configurations of nginx pagespeed (ngx_pagespeed), and the pagespeed keeps complaining about the lack of caching woff files.
This is how my configuration looks like:
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;
}
}
Do i need to define more parameters for my /static
library that contains the woff
files?
UPDATE
I altered my static location to detect if its the specific files that i wanted Cache-Control on and then added the parameters as following:
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;
}
}
ngx_pagespeed does not currently support extending the cache lifetime for woff files. You could tell Nginx to serve woff files with a long TTL or request this feature from ngx_/mod_pagespeed.