【问题标题】:Why is Modernizr loading Google fonts?为什么 Modernizr 加载 Google 字体?
【发布时间】:2014-09-03 22:31:11
【问题描述】:

我正在构建一个 Web 应用程序并刚刚安装了 ssl。

除了通过不安全的连接加载字体时遇到的这两个错误之外,一切似乎都很好。控制台表明这是 Modernizr 正在做的事情,但我不知道在哪里以及如何修复它。

这是控制台输出:

The page at 'https://myawesomewebsite.com/' was loaded over HTTPS, but ran insecure content from 'http://themes.googleusercontent.com/static/fonts/rosarivo/v1/OGdIq-p0tOtBN2VMVvO9W_esZW2xOQ-xsNqO47m55DA.woff': this content should also be loaded over HTTPS.
modernizr-2.8.0.min.js:4
The page at 'https://myawesomewebsite.com/' was loaded over HTTPS, but ran insecure content from 'http://themes.googleusercontent.com/static/fonts/inconsolata/v5/BjAYBlHtW3CJxDcjzrnZCIbN6UDyHWBl620a-IRfuBk.woff': this content should also be loaded over HTTPS.
modernizr-2.8.0.min.js:4

我实际上是在使用 TypeKit 作为我的字体,所以我不知道这些 Google 字体在页面上的作用以及为什么 Modernizr 会加载它们。

【问题讨论】:

    标签: ssl fonts modernizr


    【解决方案1】:

    在modernizr 的完整版本中,对@font-face 的CCS3 支持进行了测试。我相信这个测试代码加载一些字体只是为了看看它是否有效。

    如果您不需要,请使用modernizr 页面上的构建配置器将其从您的自定义构建库中排除。

    顺便说一句,新版本的modernizr 似乎通过SSL 加载字体。

    modernizr 2.8.3 中的测试代码

    /*>>fontface*/
    // @font-face detection routine by Diego Perini
    // javascript.nwbox.com/CSSSupport/
    
    // false positives:
    //   WebOS github.com/Modernizr/Modernizr/issues/342
    //   WP7   github.com/Modernizr/Modernizr/issues/538
    tests['fontface'] = function() {
        var bool;
    
        injectElementWithStyles('@font-face {font-family:"font";src:url("https://")}', function( node, rule ) {
          var style = document.getElementById('smodernizr'),
              sheet = style.sheet || style.styleSheet,
              cssText = sheet ? (sheet.cssRules && sheet.cssRules[0] ? sheet.cssRules[0].cssText : sheet.cssText || '') : '';
    
          bool = /src/i.test(cssText) && cssText.indexOf(rule.split(' ')[0]) === 0;
        });
    
        return bool;
    };
    /*>>fontface*/
    
    // CSS generated content detection
    tests['generatedcontent'] = function() {
        var bool;
    
        injectElementWithStyles(['#',mod,'{font:0/0 a}#',mod,':after{content:"',smile,'";visibility:hidden;font:3px/1 a}'].join(''), function( node ) {
          bool = node.offsetHeight >= 3;
        });
    
        return bool;
    };
    

    【讨论】:

    • 哦,不过我只想说,使用最新版本并不能解决问题。我现在有 2.8.3,有那个非常代码,它仍然通过 http 加载字体,我不知道为什么。使用这个文件:modernizr.com/downloads/modernizr-latest.js 我知道这是第 462 行的问题,这让我非常困惑,因为那行是:bool = node.offsetTop === 9;
    • Hrmppf,很高兴知道。我被“https://”欺骗了。你是对的。他们在那里使用了大量的黑魔法。 ;o)
    • 有同样的问题。 Modernizr 不直接加载任何 http。但是,我确实在我的 jtable 插件中发现了这些奇怪的字体。一旦我在 jtable css 页面中修复了这些字体,它就被修复了。我的猜测是modernizr 正在做它应该做的事情。如果 Modernizr 可以将 http 升级到 https,那就太好了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-22
    • 2018-07-07
    • 1970-01-01
    • 2013-11-08
    • 2020-11-05
    相关资源
    最近更新 更多