Chrome 中 CDN 后面 woff2 字体的 CORS 问题

Phi*_*bby 10 google-chrome amazon-s3 cors amazon-cloudfront woff2

我有一个带有 Cloudfront CDN 的 S3 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.
Run Code Online (Sandbox Code Playgroud)

问题是卷曲表明 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>
Run Code Online (Sandbox Code Playgroud)

在 Firefox 中一切正常,所以我猜 Chrome 正在做一个额外的验证来阻止我的字体。

Phi*_*bby 17

事实证明,问题实际上出在Content-Type. 一旦我将内容类型更改为application/font-woff2并使这些woff2文件的缓存无效,一切都顺利进行。

  • 我遇到了完全相同的问题。仅从 Chrome 加载 woff2 字体时出现 CORS 错误。但不幸的是,当我将内容类型更改为application/font-woff2后,问题仍然存在。我使用 Cmd + Shift + R 重新加载页面并清除浏览器缓存。Postman 显示 Access-Control-Allow-Origin 位于响应标头中。我错过了什么吗? (2认同)