因为最近发现blog有亿点慢,就去控制台分析了一下,发现在加载自定义字体时候花费了很多时间:

使用字体的效果

于是就去压缩了一下,使用知名的压缩项目:ecomfe/fontmin: Minify font seamlessly (github.com)

不想折腾代码了,就去下载了客户端,虽然稍微有那么亿点大:

xxxxxxxxxx53 1​2<?php3​4use RingCentral\Psr7\Response;5​6​7​8function handler($request, $context): Response{9​10 $filename = “imgurl.txt”;11​12 //从文本获取链接13​14 $pics = [];15​16 $fs = fopen($filename, “r”);17​18 while(!feof($fs)){19​20 $line=trim(fgets($fs));21​22 if($line!=’’){23​24 array_push($pics, $line);25​26 }27​28 } 29​30 //从数组随机获取链接31​32 $pic = $pics[array_rand($pics)];33​34 $num=rand(1,4);//随机变量35​36 $pic = str_replace(“https://tva4","https://tva".$num,$pic);37​38 return new Response(39​40 302,41​42 array(43​44 ‘Location’ => $pic45​46 ),47​48 “”49​50 );51​52}53​php

Fontmin

只需要把需要的文字填入即可将其他的字体去除达到压缩的目的。

可以看到,原本3m的字体压缩成了23kb。

压缩前

压缩后

2022/6/29