WOFF2 - HTTP Content-Type 响应 header 建议

WOFF2 - HTTP Content-Type response header suggestion

我正在使用 PageSpeed 进行一些网站优化。我面临下一个建议:

The following resources have no character set specified in their HTTP headers. Specifying a character set in HTTP headers can speed up browser rendering.

http://localhost:8892/.../FocoBold.woff2
http://localhost:8892/.../FocoRegular.woff2
http://localhost:8892/.../GTblack.woff2

我立即开始 google 并在 Whosebug 上找到了 relevant answer

我已将下一行添加到 .htaccess,但它对我不起作用。

AddDefaultCharset UTF-8

接下来我尝试了,但仍然没有结果。

AddType font/woff2 .woff2

有人可以帮我吗?

提前致谢

我遇到了同样的问题。

我认为 is misreporting the underlying cause which is not so much a lack of definition of the charset, but a lack of definition of the . Without that's being defined, it / most browsers assume what is being sent back is text/html, where, indeed, no charset has been defined, especially as the 文件将包含 "non-standard" (ASCII!) 个字符。

我的解决方案(如果您的 environment is significantly different, such as not allowing .htaccess 文件中可能不起作用)是将以下内容添加到所服务站点的相关根目录中的 .htaccess 中:

AddType application/x-font-woff2 .woff2

(找到这个 resource

对我有用!

在 .htaccess 中 AddType 应该在 mod_mime.c 模块中

<IfModule mod_mime.c>
AddType application/woff2 .woff2
</IfModule>