【问题标题】:Why aren't Google Fonts caching on Firefox?为什么 Google 字体不在 Firefox 上缓存?
【发布时间】:2011-05-14 23:38:05
【问题描述】:

我正在尝试在我的网站上使用嵌入的 Google 字体,并且每次有人访问该网站时,我都包含了从 Google 字体 API 下载字体的链接,但是我遇到了 Firefox 的问题,因为它看起来像每次刷新或单击新链接时都尝试下载字体。

在所有其他浏览器上,它只下载一次并像任何其他缓存的东西一样在整个站点中缓存字体。

Google 字体 API 样式表的链接如下:

<link href='http://fonts.googleapis.com/css?family=Droid+Sans&subset=latin' rel='stylesheet' type='text/css'>

【问题讨论】:

    标签: firefox google-font-api


    【解决方案1】:

    我注意到了同样的行为;用 JavaScript 加载字体似乎可以解决问题。只需在您的情况下将 'Ubuntu' 替换为 'Droid' 并在您的 &lt;head&gt; 标签之后插入以下代码块:

    <script type="text/javascript">
      WebFontConfig = {
        google: { families: [ 'Ubuntu' ] }
      };
      (function() {
        var wf = document.createElement('script');
        wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
            '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
        wf.type = 'text/javascript';
        wf.async = 'true';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(wf, s);
      })();
    </script>
    

    更多信息可以在Google Developers'字体网站上找到。

    【讨论】:

    • 很好,实际上,似乎我在 Chrome 中也遇到了问题,延迟加载也修复了它。
    猜你喜欢
    • 2011-11-14
    • 2017-06-19
    • 2016-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-20
    • 2011-02-02
    • 2017-11-07
    相关资源
    最近更新 更多