Twitter bootstrap 如何解决“;资源要求请求启用CORS…;资源已被阻止,因为无法强制执行完整性”;错误

Twitter bootstrap 如何解决“;资源要求请求启用CORS…;资源已被阻止,因为无法强制执行完整性”;错误,twitter-bootstrap,twitter-bootstrap-3,cors,subresource-integrity,Twitter Bootstrap,Twitter Bootstrap 3,Cors,Subresource Integrity,我在我的项目中使用引导图标,这会给我带来错误 子资源完整性:资源 '' 具有完整性属性,但资源要求请求 启用CORS以检查完整性,但它不是。资源 已被阻止,因为无法强制执行完整性 有人能帮我解决这个问题吗?当我们开始生产时,图标没有加载 因此,我使用下面的链接作为引导图标 %link{:href => "http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css", :integrity => "sha38

我在我的项目中使用引导图标,这会给我带来错误

子资源完整性:资源 '' 具有完整性属性,但资源要求请求 启用CORS以检查完整性,但它不是。资源 已被阻止,因为无法强制执行完整性

有人能帮我解决这个问题吗?当我们开始生产时,图标没有加载

因此,我使用下面的链接作为引导图标

%link{:href => "http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css", :integrity => "sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7", :rel => "stylesheet"}/

我认为您缺少
crossorigin=“anonymous”


当请求与同一源策略不匹配时,交叉源 属性必须存在,才能检查文件的完整性。 在外部原点和缺少交叉原点上设置完整性 浏览器将选择“故障打开”,这意味着它将加载 资源,就像未设置完整性属性一样


我试图通过Chrome DevTools控制台将jQuery插入到页面中,但遇到了这个错误。以下是我使用的代码:

// Bad code
let script = document.createElement('script');
script.src = 'https://code.jquery.com/jquery-3.2.1.min.js';
script.crossorigin = 'anonymous';
script.integrity = 'sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=';
document.head.appendChild(script);
解决方案是将
crossorigin
更改为
crossorigin
(大写O表示原点):


React服务器呈现用户注意:您需要为
crossOrigin
使用camelCase。如果通过javascript加载async,crossOrigin也区分大小写<代码>(function(){var css=document.createElement('link');css.href='https://pro.fontawesome.com/releases/v5.6.3/css/all.css';css.rel='stylesheet';css.type='text/css';css.integrity='sha384 somehash';css.crossOrigin='anonymous';console.log(css);document.getElementsByTagName('head')[0]。appendChild(css);}()这正是我需要的解决方案,完美!呜呜。。。这立刻解决了它:D
// Bad code
let script = document.createElement('script');
script.src = 'https://code.jquery.com/jquery-3.2.1.min.js';
script.crossorigin = 'anonymous';
script.integrity = 'sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=';
document.head.appendChild(script);
// Good code
let script = document.createElement('script');
script.src = 'https://code.jquery.com/jquery-3.2.1.min.js';
script.crossOrigin = 'anonymous';
script.integrity = 'sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=';
document.head.appendChild(script);