跨站请求使用到了JSONP,最近由于安全问题,给所有HTTP Response都添加了 Header:
X-Content-Type-Options: nosniff
导致浏览器发生如下的警告,JSONP数据加载失败。
Cross-Origin Read Blocking (CORB) blocked cross-origin response http://xxx?callback=callback001&_=1550113112058 with MIME type text/plain. See https://www.chromestatus.com/feature/5629709824032768 for more details.
原因为JSONP读取都资源 Content-Type为 text/plain, 修改为 Content-Type: text/javascript 后问题解决。
mozilla是这样定义X-Content-Type-Options:nosniff 的:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options
nosniff Blocks a request if the requested type is "style" and the MIME type is not "text/css", or "script" and the MIME type is not a JavaScript MIME type.
如果使用< script >加载一个javascript文件,如果MIME类型不是javascript,浏览器就会阻止加载它。JSONP正是通过这种方式实现跨域请求的。所以要求Content-Type 必须是javascript类型,例如application/javascript 和 text/javascript。 这里有个详细的列表:
https://mimesniff.spec.whatwg.org/#javascript-mime-type