css - 考虑到页面加载时间,使用本地字体文件或谷歌网络字体哪个更有效?

标签 css fonts font-face webfonts google-webfonts

我在我的网站上使用自定义字体。我可以使用本地字体文件:

src: local('Ubuntu'), url('fonts/ubuntu.woff') format('woff');

或者只使用谷歌的:

src: local('Ubuntu'), url('http://themes.googleusercontent.com/static/fonts/ubuntu/v4/_xyN3apAT_yRRDeqB3sPRg.woff') format('woff');

考虑到页面加载时间,哪个更快?

最佳答案

我设置了一个包含两个测试页面的 GAE 应用程序,一个使用 Google Web 字体,一个使用本地文件。我确保没有缓存并记录每个页面加载所花费的时间。这在 Chrome 上重复了 20 次。

结果

  • 平均加载时间(Google Web 字体):486.85 毫秒
  • 平均加载时间(本地文件):563.35 毫秒

enter image description here

代码

fonts-google.html

<!DOCTYPE html>
<html>
    <head>
        <title>title</title>
        <link href='http://fonts.googleapis.com/css?family=Ubuntu' rel='stylesheet' type='text/css'>
        <link href='both.css' rel='stylesheet' type='text/css'>
    </head>
    <body>
        <h1>This is a heading</h1>
    </body>
</html>

fonts-local.html

<!DOCTYPE html>
<html>
    <head>
        <title>title</title>
        <link href='fonts-local.css' rel='stylesheet' type='text/css'>
        <link href='both.css' rel='stylesheet' type='text/css'>
    </head>
    <body>
        <h1>This is a heading</h1>
    </body>
</html>

fonts-local.css

@font-face {
  font-family: 'Ubuntu';
  font-style: normal;
  font-weight: normal;
  src: local('Ubuntu'), url('ubuntu.woff') format('woff');
}

两个.css

h1 {
  font-family: 'Ubuntu';
}

关于css - 考虑到页面加载时间,使用本地字体文件或谷歌网络字体哪个更有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9859118/

相关文章:

javascript - 使用javascript将鼠标悬停在动画 Canvas 上

css - 哪些网络安全字体作为正文文本更易读?不应使用哪些网络安全字体?

css - ABCPdf 没有嵌入新添加的自定义字体

html - 可以为 Icon 字体分配不同的字体系列吗?

css - 字体在 mozilla 和 chrome 中不起作用

html - 为什么 Google 的开放字体示例与我在同一浏览器中实现它们时看起来不同?

javascript - 硬刷新站点后移动 View 中的 owl.carousel 响应错误

html - 具有不同高度的 Bootstrap 流体行列

javascript - 在 D3 图表的轴上启用滚动

css - Font-Face 使用绝对路径