如何在HTML中正确包含字体

时间:2016-10-11 21:34:15

标签: javascript html css fonts

目前字体包含在CSS文件中,如下所示:

@font-face {
  font-family: 'icomoon';
  src: url("../fonts/icomoon.eot");
  src: url("../fonts/icomoon.eot?#iefix") format("embedded-opentype"), url("../fonts/icomoon.woff") format("woff"), url("../fonts/icomoon.ttf") format("truetype"), url("../fonts/icomoon.svg#icomoon") format("svg");
  font-weight: normal;
  font-style: normal; }

但是当页面加载时,它会阻止渲染,直到加载这些重字体。我是否应该使用<style>标记包含在HTML中,但是有更好的方法可以优化页面加载速度吗?

1 个答案:

答案 0 :(得分:1)

即使您使用JavaScript也会相同...相反,您可以显示预加载器覆盖,直到页面完全加载为止...然后只需隐藏预加载器覆盖

https://css-tricks.com/snippets/css/using-font-face/