Dee*_*e-M 5 firefox google-font-api
我正在尝试在我的网站上使用嵌入式Google字体,并且每次有人访问网站时都包含从Google fonts API下载字体的链接,但我遇到了Firefox的问题,因为它似乎试图下载每次刷新或单击新链接时的字体.
在所有其他浏览器上,它只下载一次并将字体缓存到整个网站,就像任何其他缓存的东西一样.
Google字体API样式表的链接如下:
<link href='http://fonts.googleapis.com/css?family=Droid+Sans&subset=latin' rel='stylesheet' type='text/css'>
Run Code Online (Sandbox Code Playgroud)
小智 5
我注意到同样的行为;用 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>
Run Code Online (Sandbox Code Playgroud)
更多信息可以在Google Developers的字体网站上找到。
归档时间: |
|
查看次数: |
3404 次 |
最近记录: |