font-awesome 跨域问题

Cross-domain font-awesome

2017-11-25

如果我们使用跨域 (典型的是 CDN) 来提供 font-awesome (其他字体文件也是这样),必须像跨域 ajax 一样启用 CORS

If we serve font-awesome (more generally, any third-party fonts) from another domain (typically a CDN), we have to enable CORS, just like cross-domain ajax requests.

在 nginx 里,可以这样配置:

In nginx, we can use this:

location ~ \.(ttf|ttc|otf|eot|woff|woff2)$ {
  add_header Access-Control-Allow-Origin *;
}

现在所有大浏览器都已经执行这条规则,如果不配置 CORS,第三方字体不能正常显示。

Now all major browsers enforce this rule. Third-party fonts are ignored if served without CORS.