font-spider压缩web font字体

1、下载font-spider

基于node环境,必须先安装node。若未安装,自行去node官网下载安装。
npm i font-spider -g

2、项目目录

project
font-gzip.html
font
PingFangSC-Regular.ttf
PingFangSC-Semibold.ttf
PingFangSC-Medium.ttf
DINPro-Medium.ttf
HelveticaNeue.ttf

在这里插入图片描述

html代码:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>font字体压缩</title>
    <style>
      @font-face {
        font-family: PingFangSC-Regular;
        src: url("./font/PingFangSC-Regular.ttf");
      }
      @font-face {
        font-family: PingFangSC-Semibold;
        src: url("./font/PingFangSC-Semibold.ttf");
      }
      @font-face {
        font-family: PingFangSC-Medium;
        src: url("./font/PingFangSC-Medium.ttf");
      }
      @font-face {
        font-family: DINPro-Medium;
        src: url("./font/DINPro-Medium.ttf");
      }
      @font-face {
        font-family: HelveticaNeue;
        src: url("./font/HelveticaNeue.ttf?#font-spider");
      }
      .p1 {
        font-family: PingFangSC-Regular;
      }
      .p2 {
        font-family: PingFangSC-Semibold;
      }
      .p3 {
        font-family: PingFangSC-Medium;
      }
      .p4 {
        font-family: DINPro-Medium;
      }
      .p5 {
        font-family: HelveticaNeue;
      }
      
    </style>
  </head>
  <body>
    <p class="p1">hello,world!你好呀</p>
    <p class="p2">hello,world!你好呀</p>
    <p class="p3">hello,world!你好呀</p>
    <p class="p4">hello,world!你好呀</p>
    <p class="p5">hello,world!你好呀</p>
  </body>
</html>

3、压缩web font字体

在font-gzip.html目录下打开cmd窗口。
运行font-spider ./font-gzip.html

在这里插入图片描述
打开文件夹目录发现!!!
在这里插入图片描述

前后html加载font文件对比

压缩前:
在这里插入图片描述
压缩后:
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值