DNS预获取Google Web字体 - 哪个域名?

9
我在网页中使用了一些Google webfonts。我按照Google提供的代码,在标签中添加了以下代码: 查看这个CSS文件,发现实际的字体文件存储在'http://themes.googleusercontent.com'。
现在我想要使用DNS预获取技术,但是我应该使用哪个域名呢?是'http://fonts.googleapis.com'、'http://themes.googleusercontent.com'还是两个都要用?
1个回答

15

两者皆可:

Explicit prefetches

Typically the browser only scans the HTML for foreign domains. If you have resources that are outside of your HTML (a javascript request to a remote server or a CDN that hosts content that may not be present on every page of your site, for example) then you can queue up a domain name to be prefetched.

<link rel="dns-prefetch" href="//example.com">
<link rel="dns-prefetch" href="//ajax.googleapis.com">

You can use as many of these as you need, but it's best if they are all immediately after the Meta Charset element (which should go right at the top of the head), so the browser can act on them ASAP.

来源:https://github.com/h5bp/html5-boilerplate/blob/master/doc/extend.md#explicit-prefetches。该文档介绍了HTML5 Boilerplate中的显式预取功能,可提高网站性能。

非常酷,谢谢!但是如果我理解正确的话,如果字体出现在每个页面上,预取不会有太大意义,因为它们会被加载并缓存。你能确认一下吗? - Sven
是的,根据我的理解这是正确的;当您在不同网站上有涉及页面渲染的非HTML内容时,预取功能最为有用。也许可以尝试启用和禁用DNS预取功能来查看它是否对页面加载时间产生了显著影响。请参考:http://tools.pingdom.com/fpt/ - Anew

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接