apache 压缩/缩小@font-face 字体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1563862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Compress/Deflate @font-face fonts
提问by Torrance
I am using the @font-face CSS property to load a special font for headings on a website, and I want Apache to send the font compressed to reduce loading time.
我正在使用 @font-face CSS 属性为网站上的标题加载特殊字体,我希望 Apache 发送压缩的字体以减少加载时间。
However, the "AddOutputFilterByType" declaration in Apache 2's deflate module only accepts mime types and, as AFAIK, neither opentype nor truetype have registered mime types.
但是,Apache 2 的 deflate 模块中的“AddOutputFilterByType”声明只接受 mime 类型,并且作为 AFAIK,opentype 和 truetype 都没有注册 mime 类型。
So, how do I configure Apache to deflate/compress font.otf or font.ttf files?
那么,如何配置 Apache 以压缩/压缩 font.otf 或 font.ttf 文件?
回答by Torrance
Came up with a solution:
想出了一个解决方案:
Use Apache's AddTypedeclaration to add a custom mime type and then use that mime type in the AddOutputFilterByTypedeclaration.
使用 Apache 的AddType声明添加自定义 mime 类型,然后在AddOutputFilterByType声明中使用该 mime 类型。
For example, for opentype and truetype fonts:
例如,对于 opentype 和 truetype 字体:
Addtype font/opentype .otf
Addtype font/truetype .ttf
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css font/opentype font/truetype
Both these declarations require their appropriate modules to be active: mod_mimeand mod_deflate. And for best practice, the AddTypedeclaration should be in the mime.conf file, and the AddOutputFilterByTypedeclaration should be in the deflate.conf file. See your particular distribution's help files for enabling and configuring Apache modules.
这两个声明都要求其适当的模块处于活动状态:mod_mime和mod_deflate. 为了最佳实践,AddType声明应该在 mime.conf 文件中,AddOutputFilterByType声明应该在 deflate.conf 文件中。请参阅特定发行版的帮助文件以启用和配置 Apache 模块。

