{"id":202,"date":"2026-07-11T09:45:01","date_gmt":"2026-07-11T01:45:01","guid":{"rendered":"https:\/\/yykcj.com\/?p=202"},"modified":"2026-07-11T09:45:01","modified_gmt":"2026-07-11T01:45:01","slug":"web%e5%ad%97%e4%bd%93%e4%bc%98%e5%8c%96%e5%ae%9e%e6%88%98%ef%bc%9a%e4%bb%8e%e5%8a%a0%e8%bd%bd%e9%98%bb%e5%a1%9e%e5%88%b0%e6%80%a7%e8%83%bd%e6%8f%90%e5%8d%87%e7%9a%84%e5%ae%8c%e6%95%b4%e6%8c%87","status":"publish","type":"post","link":"https:\/\/yykcj.com\/?p=202","title":{"rendered":"Web\u5b57\u4f53\u4f18\u5316\u5b9e\u6218\uff1a\u4ece\u52a0\u8f7d\u963b\u585e\u5230\u6027\u80fd\u63d0\u5347\u7684\u5b8c\u6574\u6307\u5357"},"content":{"rendered":"<h2>\u5f15\u8a00<\/h2>\n<p>\u4f60\u662f\u5426\u9047\u5230\u8fc7\u8fd9\u6837\u7684\u60c5\u51b5\uff1a\u9875\u9762\u52a0\u8f7d\u65f6\uff0c\u6587\u5b57\u5148\u662f\u663e\u793a\u4e3a\u7cfb\u7edf\u5b57\u4f53\uff0c\u7136\u540e\u7a81\u7136\u95ea\u70c1\u53d8\u6210\u8bbe\u8ba1\u5b57\u4f53\uff1f\u8fd9\u5c31\u662f\u8457\u540d\u7684\u201cFOUT\u201d\uff08Flash of Unstyled Text\uff09\u6216\u201cFOIT\u201d\uff08Flash of Invisible Text\uff09\u3002Web\u5b57\u4f53\u867d\u7136\u8ba9\u9875\u9762\u66f4\u7f8e\u89c2\uff0c\u4f46\u82e5\u4e0d\u52a0\u4f18\u5316\uff0c\u4f1a\u4e25\u91cd\u5f71\u54cd\u7528\u6237\u4f53\u9a8c\u548c\u6027\u80fd\u6307\u6807\u3002\u672c\u6587\u5c06\u5e26\u4f60\u6df1\u5165\u7406\u89e3Web\u5b57\u4f53\u7684\u52a0\u8f7d\u8fc7\u7a0b\uff0c\u5e76\u63d0\u4f9b\u4e00\u5957\u5b8c\u6574\u7684\u4f18\u5316\u65b9\u6848\uff0c\u5305\u62ec\u5b57\u4f53\u5b50\u96c6\u5316\u3001\u9884\u52a0\u8f7d\u3001font-display\u7b56\u7565\u3001\u7f13\u5b58\u4f18\u5316\u7b49\uff0c\u6bcf\u4e00\u6b65\u90fd\u6709\u53ef\u8fd0\u884c\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<h2>1. \u7406\u89e3\u5b57\u4f53\u52a0\u8f7d\u7684\u201c\u7f6a\u9b41\u7978\u9996\u201d<\/h2>\n<p>\u5f53\u6d4f\u89c8\u5668\u9047\u5230CSS\u4e2d\u7684<code>@font-face<\/code>\u65f6\uff0c\u4f1a\u4e0b\u8f7d\u5b57\u4f53\u6587\u4ef6\u3002\u5728\u4e0b\u8f7d\u5b8c\u6210\u4e4b\u524d\uff0c\u6d4f\u89c8\u5668\u6709\u4e24\u79cd\u884c\u4e3a\uff1a<\/p>\n<ul>\n<li><strong>FOIT<\/strong>\uff1a\u9690\u85cf\u6587\u5b57\uff08\u6700\u591a3\u79d2\uff09\uff0c\u7b49\u5f85\u5b57\u4f53\u52a0\u8f7d\u3002<\/li>\n<li><strong>FOUT<\/strong>\uff1a\u7acb\u5373\u4f7f\u7528\u540e\u5907\u5b57\u4f53\uff0c\u5b57\u4f53\u52a0\u8f7d\u540e\u66ff\u6362\u3002<\/li>\n<\/ul>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5927\u591a\u6570\u6d4f\u89c8\u5668\u91c7\u7528FOIT\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u6587\u5b57\u4e0d\u53ef\u89c1\uff0c\u4e25\u91cd\u5f71\u54cd\u9996\u6b21\u5185\u5bb9\u7ed8\u5236\uff08FCP\uff09\u548c\u6700\u5927\u5185\u5bb9\u7ed8\u5236\uff08LCP\uff09\u3002<\/p>\n<h2>2. \u7b2c\u4e00\u6b65\uff1a\u4f7f\u7528font-display\u63a7\u5236\u5b57\u4f53\u6e32\u67d3\u7b56\u7565<\/h2>\n<p><code>font-display<\/code>\u662fCSS\u5c5e\u6027\uff0c\u7528\u4e8e\u63a7\u5236\u5b57\u4f53\u7684\u52a0\u8f7d\u884c\u4e3a\u3002\u5b83\u6709\u4e94\u4e2a\u503c\uff1a<code>auto<\/code>\u3001<code>block<\/code>\u3001<code>swap<\/code>\u3001<code>fallback<\/code>\u3001<code>optional<\/code>\u3002<\/p>\n<ul>\n<li><code>swap<\/code>\uff1a\u7acb\u5373\u4f7f\u7528\u540e\u5907\u5b57\u4f53\uff0c\u52a0\u8f7d\u5b8c\u6210\u540e\u66ff\u6362\uff08\u63a8\u8350\u7528\u4e8e\u54c1\u724c\u5b57\u4f53\uff09\u3002<\/li>\n<li><code>optional<\/code>\uff1a\u7ed9\u5b57\u4f53\u6781\u77ed\u65f6\u95f4\uff08\u7ea6100ms\uff09\u52a0\u8f7d\uff0c\u82e5\u8d85\u65f6\u5219\u4f7f\u7528\u540e\u5907\u5b57\u4f53\uff0c\u4e14\u4e0d\u66ff\u6362\uff08\u9002\u5408\u56fe\u6807\u5b57\u4f53\uff09\u3002<\/li>\n<li><code>fallback<\/code>\uff1a\u7c7b\u4f3coptional\uff0c\u4f46\u66ff\u6362\u7a97\u53e3\u66f4\u77ed\u3002<\/li>\n<\/ul>\n<p><strong>\u4ee3\u7801\u793a\u4f8b<\/strong>\uff1a<\/p>\n<pre><code class=\"language-css\">\n@font-face {\n    font-family: &#x27;MyCustomFont&#x27;;\n    src: url(&#x27;\/fonts\/myfont.woff2&#x27;) format(&#x27;woff2&#x27;);\n    font-display: swap; \/* \u907f\u514dFOIT *\/\n    font-weight: 400;\n    font-style: normal;\n}\n\nbody {\n    font-family: &#x27;MyCustomFont&#x27;, &#x27;Helvetica&#x27;, sans-serif;\n}\n<\/code><\/pre>\n<p><strong>\u6ce8\u610f<\/strong>\uff1a<code>swap<\/code>\u53ef\u80fd\u5bfc\u81f4\u5e03\u5c40\u504f\u79fb\uff08CLS\uff09\uff0c\u56e0\u4e3a\u540e\u5907\u5b57\u4f53\u548c\u81ea\u5b9a\u4e49\u5b57\u4f53\u7684\u5ea6\u91cf\u4e0d\u540c\u3002\u53ef\u4ee5\u901a\u8fc7\u8c03\u6574<code>size-adjust<\/code>\u6216\u4f7f\u7528<code>font-size-adjust<\/code>\u6765\u7f13\u89e3\u3002<\/p>\n<h2>3. \u7b2c\u4e8c\u6b65\uff1a\u9884\u52a0\u8f7d\u5173\u952e\u5b57\u4f53<\/h2>\n<p>\u4f7f\u7528<code><link rel=\"preload\"><\/code>\u53ef\u4ee5\u63d0\u524d\u4e0b\u8f7d\u5b57\u4f53\uff0c\u907f\u514dCSS\u89e3\u6790\u540e\u624d\u5f00\u59cb\u4e0b\u8f7d\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b<\/strong>\uff1a<\/p>\n<pre><code class=\"language-html\">\n&lt;link rel=&quot;preload&quot; href=&quot;\/fonts\/myfont.woff2&quot; as=&quot;font&quot; type=&quot;font\/woff2&quot; crossorigin&gt;\n<\/code><\/pre>\n<p><strong>\u6ce8\u610f<\/strong>\uff1a\u5fc5\u987b\u6dfb\u52a0<code>crossorigin<\/code>\u5c5e\u6027\uff0c\u56e0\u4e3a\u5b57\u4f53\u8bf7\u6c42\u901a\u5e38\u662f\u8de8\u57df\u8bf7\u6c42\uff08\u5373\u4f7f\u540c\u57df\uff09\u3002<\/p>\n<p><strong>\u6700\u4f73\u5b9e\u8df5<\/strong>\uff1a\u53ea\u9884\u52a0\u8f7d\u9996\u5c4f\u9700\u8981\u7684\u5b57\u4f53\uff0c\u907f\u514d\u8fc7\u5ea6\u9884\u52a0\u8f7d\u3002<\/p>\n<h2>4. \u7b2c\u4e09\u6b65\uff1a\u5b57\u4f53\u5b50\u96c6\u5316\u2014\u2014\u53ea\u52a0\u8f7d\u9700\u8981\u7684\u5b57\u7b26<\/h2>\n<p>\u5b57\u4f53\u6587\u4ef6\u901a\u5e38\u5305\u542b\u6570\u5343\u4e2a\u5b57\u7b26\uff0c\u4f46\u4f60\u7684\u9875\u9762\u53ef\u80fd\u53ea\u7528\u5230\u5176\u4e2d\u4e00\u5c0f\u90e8\u5206\uff08\u4f8b\u5982\u62c9\u4e01\u5b57\u6bcd\uff09\u3002\u901a\u8fc7\u5b50\u96c6\u5316\uff0c\u53ef\u4ee5\u5927\u5e45\u51cf\u5c0f\u5b57\u4f53\u6587\u4ef6\u5927\u5c0f\u3002<\/p>\n<p><strong>\u5de5\u5177<\/strong>\uff1a\u4f7f\u7528<code>glyphhanger<\/code>\u6216<code>FontTools<\/code>\u3002<\/p>\n<p><strong>\u4f7f\u7528glyphhanger\u793a\u4f8b<\/strong>\uff1a<\/p>\n<pre><code class=\"language-bash\">\n# \u5b89\u88c5\nglobal install glyphhanger\n\n# \u5206\u6790\u9875\u9762\u4e2d\u4f7f\u7528\u7684\u5b57\u7b26\nglyphhanger https:\/\/example.com --spider\n\n# \u751f\u6210\u5b50\u96c6\u5b57\u4f53\uff08\u53ea\u5305\u542b\u7528\u5230\u7684\u5b57\u7b26\uff09\nglyphhanger --whitelist=&quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&quot; --formats=woff2 --output=.\/subset-fonts\n<\/code><\/pre>\n<p><strong>\u4ee3\u7801\u96c6\u6210<\/strong>\uff1a<\/p>\n<pre><code class=\"language-css\">\n@font-face {\n    font-family: &#x27;MySubsetFont&#x27;;\n    src: url(&#x27;\/fonts\/myfont-subset.woff2&#x27;) format(&#x27;woff2&#x27;);\n    unicode-range: U+0020-007E; \/* \u53ea\u8986\u76d6ASCII\u5b57\u7b26 *\/\n    font-display: swap;\n}\n<\/code><\/pre>\n<p><strong>\u6ce8\u610f<\/strong>\uff1a<code>unicode-range<\/code>\u544a\u8bc9\u6d4f\u89c8\u5668\u4f55\u65f6\u4f7f\u7528\u8be5\u5b57\u4f53\uff0c\u907f\u514d\u4e0b\u8f7d\u4e0d\u9700\u8981\u7684\u5b57\u4f53\u3002<\/p>\n<h2>5. \u7b2c\u56db\u6b65\uff1a\u4f7f\u7528WOFF2\u683c\u5f0f\u5e76\u538b\u7f29<\/h2>\n<p>WOFF2\u662f\u5f53\u524d\u6700\u4f73\u5b57\u4f53\u683c\u5f0f\uff0c\u538b\u7f29\u7387\u6bd4WOFF\u9ad830%\u3002\u786e\u4fdd\u670d\u52a1\u5668\u652f\u6301WOFF2\u3002<\/p>\n<p><strong>\u8f6c\u6362\u5de5\u5177<\/strong>\uff1a\u4f7f\u7528<code>google\/woff2<\/code>\u6216\u5728\u7ebf\u5de5\u5177\u3002<\/p>\n<pre><code class=\"language-bash\">\n# \u4f7f\u7528woff2_compress\nwoff2_compress myfont.ttf\n<\/code><\/pre>\n<p><strong>\u670d\u52a1\u5668\u914d\u7f6e<\/strong>\uff1a\u6dfb\u52a0\u6b63\u786e\u7684MIME\u7c7b\u578b\u3002<\/p>\n<pre><code class=\"language-nginx\">\n# Nginx\nlocation \/fonts\/ {\n    add_header Content-Type font\/woff2;\n}\n<\/code><\/pre>\n<h2>6. \u7b2c\u4e94\u6b65\uff1a\u5229\u7528\u7f13\u5b58\u7b56\u7565<\/h2>\n<p>\u5b57\u4f53\u6587\u4ef6\u901a\u5e38\u4e0d\u5e38\u53d8\uff0c\u5e94\u8bbe\u7f6e\u5f3a\u7f13\u5b58\u3002<\/p>\n<p><strong>HTTP\u5934\u793a\u4f8b<\/strong>\uff1a<\/p>\n<pre><code>\nCache-Control: public, max-age=31536000, immutable\n<\/code><\/pre>\n<p><strong>Nginx\u914d\u7f6e<\/strong>\uff1a<\/p>\n<pre><code class=\"language-nginx\">\nlocation ~* \\.(woff2|woff)$ {\n    expires 1y;\n    add_header Cache-Control &quot;public, immutable&quot;;\n}\n<\/code><\/pre>\n<h2>7. \u7b2c\u516d\u6b65\uff1a\u4f7f\u7528\u5b57\u4f53\u52a0\u8f7dAPI\u8fdb\u884c\u7cbe\u7ec6\u63a7\u5236<\/h2>\n<p>CSS Font Loading API\u5141\u8bb8\u7528JavaScript\u76d1\u542c\u5b57\u4f53\u52a0\u8f7d\u72b6\u6001\uff0c\u5b9e\u73b0\u66f4\u7cbe\u7ec6\u7684\u4ea4\u4e92\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b<\/strong>\uff1a<\/p>\n<pre><code class=\"language-javascript\">\nconst font = new FontFace(&#x27;MyCustomFont&#x27;, &#x27;url(\/fonts\/myfont.woff2)&#x27;, {\n    display: &#x27;swap&#x27;\n});\n\nfont.load().then(() =&gt; {\n    document.fonts.add(font);\n    console.log(&#x27;Font loaded&#x27;);\n    \/\/ \u53ef\u4ee5\u5728\u6b64\u6dfb\u52a0\u7c7b\uff0c\u907f\u514d\u5e03\u5c40\u504f\u79fb\n    document.body.classList.add(&#x27;font-loaded&#x27;);\n}).catch(err =&gt; {\n    console.error(&#x27;Font loading failed&#x27;, err);\n});\n<\/code><\/pre>\n<h2>8. \u5b8c\u6574\u4f18\u5316\u6d41\u7a0b\u793a\u4f8b<\/h2>\n<p>\u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u81ea\u5b9a\u4e49\u5b57\u4f53<code>Poppins<\/code>\uff0c\u6211\u4eec\u5c06\u5176\u4f18\u5316\u3002<\/p>\n<h3>\u6b65\u9aa41\uff1a\u5b50\u96c6\u5316<\/h3>\n<p>\u4f7f\u7528glyphhanger\u63d0\u53d6\u9875\u9762\u7528\u5230\u7684\u5b57\u7b26\uff0c\u751f\u6210\u5b50\u96c6\u5b57\u4f53\u3002<\/p>\n<h3>\u6b65\u9aa42\uff1aCSS\u914d\u7f6e<\/h3>\n<pre><code class=\"language-css\">\n@font-face {\n    font-family: &#x27;Poppins&#x27;;\n    src: url(&#x27;\/fonts\/poppins-subset.woff2&#x27;) format(&#x27;woff2&#x27;);\n    font-display: swap;\n    font-weight: 400;\n    font-style: normal;\n    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;\n}\n\nbody {\n    font-family: &#x27;Poppins&#x27;, &#x27;Helvetica Neue&#x27;, sans-serif;\n}\n\n\/* \u540e\u5907\u5b57\u4f53\u5927\u5c0f\u8c03\u6574\uff0c\u51cf\u5c11CLS *\/\nbody {\n    font-size: 16px;\n    line-height: 1.5;\n}\n<\/code><\/pre>\n<h3>\u6b65\u9aa43\uff1aHTML\u9884\u52a0\u8f7d<\/h3>\n<pre><code class=\"language-html\">\n&lt;link rel=&quot;preload&quot; href=&quot;\/fonts\/poppins-subset.woff2&quot; as=&quot;font&quot; type=&quot;font\/woff2&quot; crossorigin&gt;\n<\/code><\/pre>\n<h3>\u6b65\u9aa44\uff1a\u670d\u52a1\u5668\u914d\u7f6e<\/h3>\n<p>Nginx\u914d\u7f6e\u7f13\u5b58\u548cMIME\u7c7b\u578b\u3002<\/p>\n<h2>9. \u5e38\u89c1\u5751\u4e0e\u8e29\u5751\u7ecf\u9a8c<\/h2>\n<ul>\n<li><strong>\u57511<\/strong>\uff1a\u9884\u52a0\u8f7d\u672a\u52a0<code>crossorigin<\/code>\u5bfc\u81f4\u5b57\u4f53\u88ab\u52a0\u8f7d\u4e24\u6b21\u3002<\/li>\n<li><strong>\u57512<\/strong>\uff1a<code>font-display: swap<\/code>\u5bfc\u81f4\u5e03\u5c40\u504f\u79fb\uff0c\u672a\u4f7f\u7528<code>size-adjust<\/code>\u6216<code>ascent-override<\/code>\u7b49\u5ea6\u91cf\u8c03\u6574\u3002<\/li>\n<li><strong>\u57513<\/strong>\uff1a\u5b50\u96c6\u5316\u65f6\u9057\u6f0f\u4e86\u67d0\u4e9b\u5b57\u7b26\uff08\u5982\u6807\u70b9\u7b26\u53f7\uff09\uff0c\u5bfc\u81f4\u9875\u9762\u663e\u793a\u7a7a\u767d\u6216\u4e71\u7801\u3002<\/li>\n<li><strong>\u57514<\/strong>\uff1a\u540c\u65f6\u52a0\u8f7d\u591a\u79cd\u5b57\u4f53\u53d8\u4f53\uff08\u5982\u7c97\u4f53\u3001\u659c\u4f53\uff09\uff0c\u6bcf\u4e2a\u90fd\u9700\u8981\u5355\u72ec@font-face\u3002<\/li>\n<\/ul>\n<h2>10. \u603b\u7ed3<\/h2>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u663e\u8457\u63d0\u5347Web\u5b57\u4f53\u7684\u52a0\u8f7d\u6027\u80fd\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528<code>font-display: swap<\/code>\u907f\u514dFOIT<\/li>\n<li>\u9884\u52a0\u8f7d\u5173\u952e\u5b57\u4f53<\/li>\n<li>\u5b50\u96c6\u5316\u51cf\u5c11\u6587\u4ef6\u5927\u5c0f<\/li>\n<li>\u4f7f\u7528WOFF2\u683c\u5f0f<\/li>\n<li>\u8bbe\u7f6e\u5f3a\u7f13\u5b58<\/li>\n<li>\u5229\u7528JavaScript API\u7cbe\u7ec6\u63a7\u5236<\/li>\n<\/ul>\n<p><strong>\u5ef6\u4f38\u9605\u8bfb<\/strong>\uff1a<\/p>\n<ul>\n<li><a href=\"https:\/\/developers.google.com\/fonts\/docs\/optimize\">Google Fonts\u4f18\u5316\u6307\u5357<\/a><\/li>\n<li><a href=\"https:\/\/drafts.csswg.org\/css-fonts-4\/\">CSS Fonts Module Level 4<\/a><\/li>\n<li><a href=\"https:\/\/web.dev\/font-display\/\">Performance of Web Fonts<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Web\u5b57\u4f53\u52a0\u8f7d\u5e38\u5bfc\u81f4\u9875\u9762\u95ea\u70c1\u548c\u6027\u80fd\u74f6\u9888\u3002\u672c\u6587\u6df1\u5165\u5206\u6790\u5b57\u4f53\u52a0\u8f7d\u673a\u5236\uff0c\u63d0\u4f9b\u4ece\u9884\u52a0\u8f7d\u3001\u5b50\u96c6\u5316\u5230\u5b57\u4f53\u663e\u793a\u7b56\u7565\u7684\u5b8c\u6574\u4f18\u5316\u65b9\u6848\uff0c\u9644\u5e26\u53ef\u8fd0\u884c\u7684\u4ee3\u7801\u793a\u4f8b\uff0c\u52a9\u4f60\u6253\u9020\u6d41\u7545\u7684\u6587\u5b57\u4f53\u9a8c\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[120,117,119,49,118,6],"class_list":["post-202","post","type-post","status-publish","format-standard","hentry","category-3","category-4","tag-font-display","tag-web","tag-woff2","tag-49","tag-118","tag-6"],"_links":{"self":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts\/202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=202"}],"version-history":[{"count":0,"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts\/202\/revisions"}],"wp:attachment":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}