html网页引用中文字体,解决加载缓慢办法

时间:2021-04-29 16:04:33

【ttf 压缩】html网页引用中文字体,文件过大,加载缓慢的解决办法【字蛛】【web font】

【字蛛】http://font-spider.org/

先安装好 NodeJS,然后执行:

npm install font-spider -g

html网页引用中文字体,解决加载缓慢办法

安装后,会看到一堆报错、警告,不必理会

在 CSS 中使用 WebFont:

/*声明 WebFont*/
@font-face {
font-family: '方正兰亭刊黑_GBK';
src: url('../fonts/方正兰亭刊黑_GBK.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
/*使用选择器指定字体*/
body{
font-family: '方正兰亭刊黑_GBK';
}

@font-face 中的 src 定义的 .ttf 文件必须存在

运行 font-spider 命令:

font-spider D:\web\helloWorld\*.html 

页面依赖的字体将会自动压缩好