带有 Google Fonts 的 Webfont 加载器不使用 https



我正在为我的网站上的字体使用 webfont 加载器,并具有以下设置:

.HTML

<script src="https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js" integrity="sha384-pvXSwSU09c+q9mPyY++ygUHWIYRoaxgnJ/JC5wcOzMb/NVVu+IDniiB9qWp3ZNWM" crossorigin="anonymous"></script>

.JS

WebFont.load({
  google: {
    families: ['Libre Franklin']
  }
});

然后在我的.htaccess中,我将样式表的源代码设置为我的内容安全策略的一部分,如下所示:

style-src 'self' https://fonts.googleapis.com;

但是当站点加载字体时,它正在使用字体的http://源,因此它被CSP阻止,我在控制台中收到此错误消息:

Refused to load the stylesheet 'http://fonts.googleapis.com/css?family=Libre+Franklin' because it violates the following Content Security Policy directive: "style-src 'self' https://fonts.googleapis.com".

如何确保网站正在加载样式表的 https://版本?

webfonts.js使用location.protocol来调整请求httphttps,当您的项目位于域中时https它将更改为https

相关内容

最新更新