使用glyphhanger进行字体包子集优化

163 阅读1分钟

字体包大小优化

背景

在做门户网站时,引入了字体包,考虑用子集优化的方式,在构建阶段,缩小字体包的大小。

image.png

woff2属于压缩过的字体格式,无法编辑,所以需要使用ttf格式作为输入,在ttf基础上缩小字体包

noglob glyphhanger http://localhost:3000 --spider --subset=*.ttf --formats=woff2  --output=subsets

为什么使用noglob?

指定--spider爬取页面中具有<a>tag子路由的页面

image.png

并在css中将字体包改为subset包

image.png

优化结果

image.png

image.png

一些有用的链接