笔者在使用某个免费空间的时候遇到一个问题,无法加载字体文件,该免费空间无法设置MIME类型,所以肯定字体文件就无法访问了。
于是曲线救国,把样式放到另外一台IIS服务器上,引用另外一个域名下的样式文件,但是出现了跨域问题:
Access to Font at 'http://ftp6239170.host702.zhujiwu.me/public/bootstrap/fonts/glyphicons-halflings-regular.woff2' from origin 'http://www.shanghai310.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.shanghai310.com' is therefore not allowed access. The response had HTTP status code 404.
之前都是调用接口发生跨域问题,没想到字体文件也会有跨域问题。
其实在IIS中可以设置HTTP响应标头来解决跨域问题,如图所示:
在HTTP响应标头中添加Access-Control-Allow-Origin:*,Access-Control-Allow-Headers:Content-Type, api_key, Authorization即可