Including Google Web Fonts link or import?
What is the preferred way of including Google Web Fonts to a page?
via the link tag?
<link href='http://fonts.googleapis.com/css?family=Judson:400,400italic,700' rel='stylesheet' type='text/css'>
via import in a stylesheet?
@import url(http://fonts.googleapis.com/css?family=Kameron:400,700);
or use the web font loader
https://developers.google.com/webfonts/docs/webfont_loader
For 90%+ of the cases you likely want the <link>
tag. As a rule of thumb, you want to avoid @import
rules because they defer the loading of the included resource until the file is fetched.. and if you have a build process which "flattens" the @import's, then you create another problem with webfonts: dynamic providers like Google WebFonts serve platform specific versions of the fonts, so if you simply inline the content, then you'll end up with broken fonts on some platforms.
Now, why would you use the web font loader? If you need complete control over how the fonts are loaded. Most browsers will defer painting the content to the screen until all of the CSS is downloaded and applied - this avoids the "flash of unstyled content" problem. The downside is.. you may have an extra pause and delay until the content is visible. With the JS loader, you can define how and when the fonts become visible.. for example, you can even fade them in after the original content is painted on the screen.
Once again, the 90% case is the <link>
tag: use a good CDN and the fonts will come down quick and even more likely, be served out of the cache.
For more info, and an in-depth look at Google Web Fonts, check out this GDL video: https://www.youtube.com/watch?v=sqesm0euf9M
链接地址: http://www.djcxy.com/p/65056.html