我有一个由Cloudfront CDN前置的S3 Bucket。在那个bucket中,我有一些woff2字体,这些字体被自动标记为内容类型octet-stream
。当尝试从生产网站上的CSS文件加载该字体时,我收到以下错误:
Access to Font at 'https://cdn.example.com/fonts/my-font.woff2' from origin
'https://www.live-website.com' has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'https://www.live-website.com' is therefore not allowed access.
问题在于使用curl命令可以展示出Access-Control-Allow-Origin
的存在:
HTTP/1.1 200 OK
Content-Type: binary/octet-stream
Content-Length: 98488
Connection: keep-alive
Date: Wed, 08 Aug 2018 19:43:01 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
Access-Control-Max-Age: 3000
Last-Modified: Mon, 14 Aug 2017 14:57:06 GMT
ETag: "<redacted>"
Accept-Ranges: bytes
Server: AmazonS3
Age: 84847
X-Cache: Hit from cloudfront
Via: 1.1 <redacted>
X-Amz-Cf-Id: <redacted>
在Firefox中一切都正常,所以我想Chrome进行了额外的验证,阻止了我的字体。
Translated Text:在Firefox中一切都正常,所以我想Chrome进行了额外的验证,阻止了我的字体。