<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:wfw="http://wellformedweb.org/CommentAPI/">
<channel>
<title>ikn0w1T&#039;s blog - diy</title>
<link>https://blog.lihan.cyou/index.php/tag/diy/</link>
<atom:link href="https://blog.lihan.cyou/index.php/feed/tag/diy/" rel="self" type="application/rss+xml" />
<language>zh-CN</language>
<description></description>
<lastBuildDate>Wed, 16 Apr 2025 13:41:00 +0800</lastBuildDate>
<pubDate>Wed, 16 Apr 2025 13:41:00 +0800</pubDate>
<item>
<title>修改网站字体为霞鹜文楷</title>
<link>https://blog.lihan.cyou/index.php/archives/84/</link>
<guid>https://blog.lihan.cyou/index.php/archives/84/</guid>
<pubDate>Wed, 16 Apr 2025 13:41:00 +0800</pubDate>
<dc:creator>ikn0w1T</dc:creator>
<description><![CDATA[逛博客时发现了一个好看的字体-霞鹜文楷下载地址字体预览霞鹜文楷的ttf文件都比较大在20MB左右，可以使用在线工具将ttf文件转换为woff2方便网站加载。我这里选择上传到cdn以便加快字体加载...]]></description>
<content:encoded xml:lang="zh-CN"><![CDATA[
<p>逛博客时发现了一个好看的字体-霞鹜文楷</p><p><a href='https://github.com/lxgw/LxgwWenKai'>下载地址</a></p><p>字体预览</p><p><img src="https://image.lihan.cyou/20250416134618825.png" referrerpolicy="no-referrer"></p><p>霞鹜文楷的ttf文件都比较大在20MB左右，可以使用在线工具将ttf文件转换为woff2方便网站加载。我这里选择上传到cdn以便加快字体加载速度，因为本人使用的博客主题后台提供了自定义字体的功能，所以只需要填入链接即可，另外也要注意填入的链接要为https，原因和之前关于图床提到的一样，因为网站是https的请求http会无法响应，或者在cdn中设置为强制https应该也可以（我没有尝试过）。</p><hr />
<p>经过使用发现，由于字体文件确实有点大，网站中字体的加载速度来到了1.8~1.9秒。网上查询后发现建议将ttf格式转换为woff2格式。</p>
<p><a href='https://cloudconvert.com/ttf-to-woff2'>在线转换工具地址</a></p>
<p>最后发现字体加载速度确实加快了，但是仍在0.8秒左右，先这样吧，目前也只影响首次进入网站会有一个小停顿，后续如果遇到更佳的方法再进行尝试。</p>
<hr />
<p>最后的解决方案</p>
<p>结果查找资料发现可以使用fonttools工具对需要使用的ttf文件就行特定文字的提取，我们平时写博客其实常用字就够用了，这里选择常用6500字，<a href='https://pan.baidu.com/s/1biNJOcI7IaoRqg7NJrYeLA?pwd=p573'>下载地址</a></p>
<p>fonttools的使用python环境就可以完成</p>
<p>安装</p>
<pre><code class='language-python' lang='python'>pip install fonttools
</code></pre>
<p>使用</p>
<pre><code class='language-python' lang='python'>pyftsubset 拟瘦身的字体文件 --text-file=要保留的常用字文件
</code></pre>
<p>例如我的命令</p>
<pre><code class='language-python' lang='python'>pyftsubset .\LXGWWenKaiLite-Regular.ttf --text-file=.\c6500.txt
</code></pre>
<p>就可以得到一个精简后的ttf文件，这个时候再配合转换为woff2文件即可进一步压缩文件大小。</p>
<p>最终实现 11.1 MB--&gt;3.13 MB --&gt;1.43 MB</p>
<p>最终响应速度维持在65ms左右，至此网页修改字体并优化完成。</p>
<hr />
<p>再次优化，使用预加载实现浏览器先请求该字体文件，避免出现白屏或者闪烁的情况。</p>
<p>进入主题的文件夹打开head.php，在前面添加如下内容即可</p>
<pre><code class='language-html' lang='html'>&lt;link rel=&quot;preload&quot; href=&quot;https://image.lihan.cyou/LXGWWenKaiLite-Regular.subset.woff2&quot; as=&quot;font&quot; type=&quot;font/woff2&quot; crossorigin=&quot;anonymous&quot;&gt;
</code></pre>
]]></content:encoded>
<slash:comments>1</slash:comments>
<comments>https://blog.lihan.cyou/index.php/archives/84/#comments</comments>
<wfw:commentRss>https://blog.lihan.cyou/index.php/feed/tag/diy/</wfw:commentRss>
</item>
</channel>
</rss>