有效的压缩字体方法
该方法是单纯对字体包的压缩,压缩后可应用于网页中,提高加载速度。
1、使用 fonttools
压缩字体文件
需要 Python
环境,并已安装好 pip
。
使用 pip
来安装 fonttools
pip install fonttools
自行搜索下载已经整理好的字体编码列表文件 sc_unicode.txt
。
输入命令
pyftsubset YouYuan.ttf --unicodes-file=sc_unicode.txt
执行后
整个流程的命令截图(安装python -》安装pip-》压缩文字):
2、转换成woff2
字体文件
在这个国外的平台里,把字体换成woff2格式CloudConvert>File converter service - more than 200 different audio, video, document, ebook, archive, image, spreadsheet and presentation formats supported.https://cloudconvert.com/
最后只有712kb
总结:从开始6m多的字体压缩成700多kb的字体文件,需要按照按照上面2步走。
===
有效压缩js的方法
先安装: npm i -g uglify-js
再在 项目根目录下 :uglifyjs assets\theme.dev.js -o assets\theme.js