如何在Firefox中获取加载跨域的字体

时间:2014-02-13 17:09:31

标签: css apache fonts cdn

我正在使用limelight CDN作为静态文件。我在本机firefox检查器中收到错误:

可下载字体:下载失败(font-family:“nimbus-bold”样式:正常权重:正常拉伸:正常src索引:1):不允许错误的URI或跨站点访问 来源:http://cdn-store.example.com/fonts/nimbussanspot-bold-webfont.woff

CSS:

@font-face {
font-family: 'nimbus-bold';
src: url('/fonts/nimbussanspot-bold-webfont.eot');
src: url('/fonts/nimbussanspot-bold-webfont.eot%3F%23iefix') format("embedded-opentype");
src: url('/fonts/nimbussanspot-bold-webfont.woff') format("woff");
src: url('/fonts/nimbussanspot-bold-webfont.ttf') format("truetype");
src: url('/fonts/nimbussanspot-bold-webfont.svg%23nimbus_sans_p_otbold') format("svg");
font-weight: normal;
font-style: normal;
}

我尝试了以下内容,但没有帮助:

<FilesMatch "\.(ttf|otf|woff)$">
<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>

-bash-4.1$ curl -I http://cdn-store.example.com/fonts/nimbussanspot-bold-webfont.woff
HTTP/1.1 200 OK
Date: Thu, 13 Feb 2014 16:58:05 GMT
Server: Apache/2.2.15 (Oracle)
Last-Modified: Thu, 13 Feb 2014 15:45:31 GMT
Accept-Ranges: bytes
Vary: Accept-Encoding,User-Agent
Access-Control-Allow-Origin: *
Content-Type: text/plain
Content-Length: 24040
Connection: keep-alive

-bash-4.1$ curl -I http://store.example.com/fonts/nimbussanspot-bold-webfont.woff
HTTP/1.1 200 OK
Date: Thu, 13 Feb 2014 17:04:10 GMT
Server: Apache/2.2.15 (Oracle)
Last-Modified: Thu, 13 Feb 2014 15:45:31 GMT
ETag: "146124-5de8-4f24b944b4eff"
Accept-Ranges: bytes
Content-Length: 24040
Vary: Accept-Encoding,User-Agent
Access-Control-Allow-Origin: *
Connection: close
Content-Type: text/plain

编辑: 使用'AddType'指令我得到以下结果,但字体不加载

$ curl -I http://store.example.com/fonts/nimbussanspot-bold-webfont.woff
HTTP/1.1 200 OK
Date: Fri, 14 Feb 2014 15:09:02 GMT
Server: Apache/2.2.15 (Oracle)
Last-Modified: Thu, 13 Feb 2014 15:45:31 GMT
ETag: "146124-5de8-4f24b944b4eff"
Accept-Ranges: bytes
Content-Length: 24040
Vary: Accept-Encoding,User-Agent
Access-Control-Allow-Origin: *
Connection: close
Content-Type: application/x-font-woff

$ curl -I http://cdn-store.example.com/fonts/nimbussanspot-bold-webfont.woff
HTTP/1.1 200 OK
Server: Apache/2.2.15 (Oracle)
Accept-Ranges: bytes
Vary: Accept-Encoding,User-Agent
Access-Control-Allow-Origin: *
Content-Type: application/x-font-woff
Age: 55
Date: Fri, 14 Feb 2014 15:08:59 GMT
Last-Modified: Thu, 13 Feb 2014 15:45:31 GMT
Content-Length: 24040
Connection: keep-alive

2 个答案:

答案 0 :(得分:2)

您的网页文件以text/plain内容类型提供,而不是application/x-font-woff等正确文件。

在apache配置文件中尝试这样的操作,看看是否有帮助:

<Location /webfont>
   Header set Access-Control-Allow-Origin "*"
   AddType application/vnd.ms-fontobject .eot
   AddType application/x-font-ttf .ttf
   AddType application/x-font-woff .woff
</Location>

答案 1 :(得分:2)

在您的服务器上,您需要为字体添加Access-Control-Allow-Origin.htaccess添加:

<FilesMatch "\.(ttf|otf|eot|woff|woff2)$">
    <IfModule mod_headers.c>
        Header set Access-Control-Allow-Origin "*"
    </IfModule>
</FilesMatch>