通过Firebase CDN加载字体

时间:2016-03-31 19:33:35

标签: firebase firebase-hosting

我正在尝试通过Firebase加载字体(cdn.domain.co.uk),但Chrome会因CORS而阻止响应,并出现以下错误:

Font from origin 'https://cdn.domain.co.uk' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://domain.co.uk' is therefore not allowed access.

有什么方法吗?

1 个答案:

答案 0 :(得分:2)

请注意任何遇到此问题的人:阅读文档

将以下内容应用到firebase.json并相应更改值。

"headers": [ {
    "source" : "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
    "headers" : [ {
        "key" : "Access-Control-Allow-Origin",
        "value" : "*"
    } ]
} ]

Firebase提供的完整文档:https://www.firebase.com/docs/hosting/guide/full-config.html