大网数据广告活动
服务器运维问答

Nginx not compressing tff files

· 52CE 我爱测

I have added this to my nginx config gzip_types application/javascript application/font-ttf text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vn…

问题原文

原帖链接 · nadermx · CC BY-SA 4.0

I have added this to my nginx config

gzip_types application/javascript application/font-ttf text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;

But when I run a webpagetest.org I get this result

Use gzip compression for transferring compressable responses: 67/100

707.7 KB total in compressible text, target size = 471.6 KB - potential savings = 236.1 KB

WARNING - (167.7 KB, compressed = 88.1 KB - savings of 79.5 KB) - https://example.com/static/fonts/Roboto-Regular.ttf
WARNING - (166.4 KB, compressed = 88.0 KB - savings of 78.5 KB) - https://example.com/static/fonts/Roboto-Light.ttf
WARNING - (166.8 KB, compressed = 88.7 KB - savings of 78.1 KB) - https://example.com/static/fonts/Roboto-Bold.ttf

Should I add in a different type of gzip_types to the config?

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

The default nginx configuration shipped with nginx doesn't include a MIME type for TrueType font files. You can see the MIME types that are configured in the shipped file /etc/nginx/mime.types.

You can add to the existing types block in your nginx configuration.

types {

    .....

    application/x-font-ttf ttf;
}

Though you should probably use the official MIME type font/ttf rather than the interim MIME type that you had tried to use.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-10-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。