6

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

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

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

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

1 回答 1

4

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

<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的字体网站上找到更多信息。

于 2011-01-06T08:35:38.693 回答