{"id":7848,"date":"2018-07-25T00:51:14","date_gmt":"2018-07-24T16:51:14","guid":{"rendered":"https:\/\/www.zhangxinxu.com\/wordpress\/?p=7848"},"modified":"2018-08-02T01:17:02","modified_gmt":"2018-08-01T17:17:02","slug":"known-woff2-mime-convert","status":"publish","type":"post","link":"https:\/\/www.zhangxinxu.com\/wordpress\/2018\/07\/known-woff2-mime-convert\/","title":{"rendered":"\u4e86\u89e3woff2\u5b57\u4f53\u53ca\u8f6c\u6362"},"content":{"rendered":"<p>by <a href=\"https:\/\/www.zhangxinxu.com\/\">zhangxinxu<\/a> from <a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=5474\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=5474<\/a><br \/>\n\u672c\u6587\u53ef\u5168\u6587\u8f6c\u8f7d\uff0c\u4f46\u9700\u5f97\u5230\u539f\u4f5c\u8005\u4e66\u9762\u8bb8\u53ef\uff0c\u540c\u65f6\u4fdd\u7559\u539f\u4f5c\u8005\u548c\u51fa\u5904\uff0c\u6458\u8981\u5f15\u6d41\u5219\u968f\u610f\u3002<\/p>\n<h3>\u4e00\u3001woff2\u5b57\u4f53\u6982\u89c8<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201807\/woff2-thumb.jpg\" width=\"242\" height=\"150\" alt=\"\u6587\u7ae0\u5934\u56fe\" class=\"alignleft thumb size-medium\" \/><\/p>\n<p>woff\u5b57\u4f53\u57282012\u5e7412\u6708\u88abWorld Wide Web Consortium (W3C)\u63a8\u8350\u4f7f\u7528\uff0cIE9+\u6d4f\u89c8\u5668\u652f\u6301\u3002<\/p>\n<p>woff2\u5b57\u4f53\u6700\u65e9\u5728\u57282013\u5e747\u6708Chrome Canary\u7248\u672c\u4e0a\u53ef\u4ee5\u4f7f\u7528\uff0c\u53d1\u5c55\u5230\u73b0\u5728\uff0c\u51e0\u4e4e\u5df2\u7ecf\u6210\u4e3a\u81ea\u5b9a\u4e49\u56fe\u6807\u5b57\u4f53\u4f7f\u7528\u7684\u6807\u914d\uff0c\u76ee\u524d\u6d4f\u89c8\u5668\u7684\u517c\u5bb9\u6027\u5df2\u7ecf\u76f8\u5f53\u4e0d\u9519\u4e86\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201807\/2018-07-24_235045.png\" width=\"472\" height=\"234\" alt=\"woff2\u517c\u5bb9\u6027\u622a\u56fe\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u57fa\u672c\u4e0a\uff0c\u5728web\u5e94\u7528\u4e2d\uff0cttf\u8fd8\u6709svg\u8fd9\u79cd\u5b57\u4f53\u5c31\u6ca1\u6709\u51fa\u73b0\u7684\u5fc5\u8981\u4e86\u3002<\/p>\n<p>woff2\u5b57\u4f53\u6700\u5927\u7684\u4f18\u5148\u5728\u4e8e\u4f53\u79ef\u4f20\u8f93\u5c0f\uff0c\u501f\u7528Google Chrome\u5b98\u65b9\u8bdd\u8bf4\uff1a<\/p>\n<blockquote><p>\u65b0\u7684WOFF 2.0 Web \u5b57\u4f53\u538b\u7f29\u683c\u5f0f\u5e73\u5747\u8981\u6bd4WOFF 1.0\u5c0f30%\u4ee5\u4e0a\uff08\u67d0\u4e9b\u60c5\u51b5\u53ef\u4ee5\u8fbe\u523050%+\uff09 <\/p><\/blockquote>\n<p>\u4e0b\u9762\u662f\u4e00\u5f20woff vs woff2\u5b57\u4f53\u5927\u5c0f\u5bf9\u6bd4\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201807\/woff-vs-woff2.png\" width=\"500\" height=\"370\" alt=\"woff\u5bf9\u6bd4woff2\u56fe\" class=\"alignnone size-medium\" \/><\/p>\n<h3>\u4e8c\u3001TTF\u8f6cWOFF2<\/h3>\n<p><strong>Node.js\u7248\u672c<\/strong><\/p>\n<p>\u53ef\u4ee5\u53c2\u8003\u8fd9\u4e2aGithub\u9879\u76ee\uff1a<a href=\"https:\/\/github.com\/nfroidure\/ttf2woff2\" rel=\"nofollow\" target=\"_blank\">https:\/\/github.com\/nfroidure\/ttf2woff2<\/a><\/p>\n<p>\u5e94\u8be5\u662f\u5728google\u5b98\u65b9<a href=\"https:\/\/github.com\/google\/woff2\" rel=\"nofollow\" target=\"_blank\">woff2\u9879\u76ee<\/a>\u5916\u9762\u5305\u4e86\u4e00\u5c42\u3002<\/p>\n<p>\u4f7f\u7528\u793a\u610f\u5982\u4e0b\uff1a<\/p>\n<pre>var fs = require('fs');\nvar ttf2woff2 = require('ttf2woff2');\n\nvar input = fs.readFileSync('font.ttf');\n\nfs.writeFileSync('font.woff2', ttf2woff2(input));<\/pre>\n<p><strong>\u5728\u7ebfTTF\u8f6cwoff2<\/strong><\/p>\n<p>\u4e0b\u97622\u4e2a\u5730\u5740\u90fd\u53ef\u4ee5\u5728\u7ebf\u8f6c\u6362\uff1a<\/p>\n<ul>\n<li><a href=\"http:\/\/www.fontsquirrel.com\/tools\/webfont-generator\" rel=\"nofollow\" target=\"_blank\">http:\/\/www.fontsquirrel.com\/tools\/webfont-generator<\/a><\/li>\n<li><a href=\"http:\/\/everythingfonts.com\/ttf-to-woff2\" rel=\"nofollow\" target=\"_blank\">http:\/\/everythingfonts.com\/ttf-to-woff2<\/a><\/li>\n<\/ul>\n<p>\u6211\u4e2a\u4eba\u90fd\u662f\u4f7f\u7528fontsquirrel\u8fd9\u4e2a\u7f51\u7ad9\u7684\uff0c\u5f88\u591a\u5e74\u524d\u6211\u5c31\u63a8\u8350\u8fc7\uff0c\u7b80\u5355\u4e09\u6b65\u66f2\uff0c1. \u4e0a\u4f20\uff1b 2. \u786e\u8ba4\u7248\u6743\uff1b 3. \u4e0b\u8f7d\u3002\u4eca\u5929\u8fd8\u8bd5\u7528\u4e86\u4e0b\uff0c\u5f88\u4e0d\u9519\uff0c\u8fde<code>@font-face<\/code>\u76f8\u5173CSS\u4ee3\u7801\u90fd\u4e00\u5e76\u751f\u6210\u4e86\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201807\/2018-07-25_001511.png\" width=\"591\" height=\"277\" alt=\"fontsquirrel\u8f6cwoff2\u622a\u56fe\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u4f1a\u751f\u6210woff\u548cwoff2\u4e24\u4e2a\u5b57\u4f53\uff0c\u5982\u679c\u4f60\u7684\u9879\u76ee\u65e0\u9700\u517c\u5bb9IE8\u6d4f\u89c8\u5668\uff0c\u8db3\u591f\u4e86\u3002<\/p>\n<hr>\n<p>\u5bf9\u4e86WOFF2\u5b57\u4f53\u8c8c\u4f3c\u662f\u53ef\u4ee5\u8fd8\u539f\u6210TTF\u5b57\u4f53\u7684\uff0c<\/p>\n<p>\u56e0\u4e3a\u6211\u5728<a href=\"https:\/\/github.com\/google\/woff2\" rel=\"nofollow\" target=\"_blank\">google\u5b98\u65b9<\/a>\u9879\u76ee\u4e2d\u770b\u5230\u4e86\u4e0b\u9762\u7684\u793a\u610f\u4ee3\u7801\uff1a<\/p>\n<pre>woff2_compress myfont.ttf\nwoff2_decompress myfont.woff2<\/pre>\n<p>\u5f88\u663e\u7136\uff0c\u4e0b\u9762\u4e00\u884c\u662f\u201c\u53cd\u538b\u7f29\u201d\uff0c\u591a\u534a\u5c31\u662f\u8fd8\u539f\u5b57\u4f53\u7684\u610f\u601d\uff0c\u4e0d\u8fc7\u5177\u4f53\u5982\u4f55\u8fd0\u884c\u6211\u5e76\u6ca1\u6709\u4eb2\u81ea\u5c1d\u8bd5\uff0c\u5982\u679c\u8c01\u6709\u7ecf\u9a8c\uff0c\u6b22\u8fce\u5206\u4eab\u4e0b\uff0c\u6211\u53ca\u65f6\u8865\u5145\u3002<\/p>\n<h3>\u4e09\u3001WOFF2\u5728CSS\u4e2d\u7684\u4f7f\u7528<\/h3>\n<p>\u5982\u4e0b\uff0c\u7531\u4e8eIE13-\u548c\u90e8\u5206\u56fd\u4ea7Android\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\uff0c\u56e0\u6b64\u8fd8\u9700\u8981WOFF\u515c\u5e95\uff1a<\/p>\n<pre>@font-face {\n    font-family: MyFont;\n    src: url('myfont.woff2') format('woff2'),\n        url('myfont.woff') format('woff');\n}<\/pre>\n<p>\u5982\u679c\u4f60\u7684\u5b57\u4f53\u4f53\u79ef\u4e0d\u662f\u5f88\u5927\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5base64\u5185\u5d4c\u5728CSS\u4e2d\uff0c\u52a0\u8f7d\u4f53\u9a8c\u8981\u6bd4\u5916\u94fe\u5b57\u4f53\u8981\u597d\u4e00\u4e9b\uff0c\u5373\u4fbf\u4f60\u4f7f\u7528\u4e86\u65b0\u7684CSS3 <code>font-display<\/code>\u5c5e\u6027\u3002<\/p>\n<p>\u8bed\u6cd5\u662f\u7c7b\u4f3c\u7684\uff1a<\/p>\n<pre>@font-face {\n    font-family: MyFont;\n    src: url('data:font\/woff2;base64,...') format('woff2'),\n        url('data:font\/woff;base64,...') format('woff');\n}<\/pre>\n<p>\u5982\u4f55\u8f6cbase64 encoded\u5b57\u7b26\u4e32\u5462\uff1f<\/p>\n<p>\u8fd9\u91cc\u6709\u6211\u81ea\u5df1\u5f04\u7684\u4e00\u4e2a\u4efb\u610f\u6587\u4ef6\u8f6cbase64\u7684\u9875\u9762\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/sp\/base64.html\" rel=\"noopener\" target=\"_blank\">\/sp\/base64.html<\/a>\u3002\u4efb\u610f\u6587\u4ef6\u62d6\u8fdb\u53bb\u90fd\u53ef\u4ee5\u8f6c\u6210base64\uff0c\u5f53\u7136\u4e5f\u5305\u62ecwoff2\u6587\u4ef6\u3002<\/p>\n<p>\u4e0d\u8fc7\uff0c\u6839\u636e\u6211\u7684\u6d4b\u8bd5\uff0cwoff2\u5b57\u4f53\u8f6c\u6362\u540e\u6ca1\u6709\u663e\u793amime type\u503c\uff0c\u76f4\u63a5\u5c31\u662f<code>data;base64,...<\/code>\uff0c\u6211\u590d\u5236\u5230CSS\u4ee3\u7801\u4e2d\u4e00\u6d4b\u8bd5\uff0c\u563f\uff0c\u6548\u679c\u5b8c\u5168\u652f\u6301\u3002\u5f53\u7136\uff0c\u5982\u679c\u4f60\u4e0d\u653e\u5fc3\uff0c\u53ef\u4ee5\u624b\u52a8\u52a0\u4e2a<code>font\/woff2<\/code>\u3002<\/p>\n<h3>\u56db\u3001\u5176\u4ed6\u9700\u8981\u77e5\u9053\u7684\u77e5\u8bc6<\/h3>\n<ul>\n<li>WOFF\u5b57\u4f53\u6ca1\u6709\u5fc5\u8981\u518d\u5f00\u542fGZIP\uff0c\u56e0\u4e3a\u8fd9\u4e2a\u5b57\u4f53\u6587\u672c\u672c\u8eab\u5c31\u662f\u538b\u7f29\u8fc7\u7684\u3002<\/li>\n<li>WOFF 2.0\u7684mime type\u503c\uff0c\u600e\u4e48\u8bf4\u5462\uff0c\u6709\u4e9b\u8bb8\u5c0f\u4e89\u8bae\u3002Google\u4f7f\u7528font\/woff2\uff0c\u800cW3C\u5219\u63a8\u8350application\/font-woff2\u3002\u6211\u4e2a\u4eba\u7684\u5efa\u8bae\u662f\u8fd9\u6837\u7684\uff1a\u5728CSS base64\u5b57\u4f53\u8868\u793a\u65f6\u5019\u4f7f\u7528Google\u7684font\/woff2\uff0c\u6bd5\u7adf\u662fweb\u5448\u73b0\uff1b\u7136\u540e\u670d\u52a1\u5668\u914d\u7f6e\u8d70application\/font-woff2\u3002\n<p>NGINX: WOFF2 mime type<\/p>\n<pre>types {\n    application\/font-woff2  woff2;\n}<\/pre>\n<p>APACHE: WOFF2 mime type<\/p>\n<pre>AddType  application\/font-woff2  .woff2<\/pre>\n<p>IIS\uff1aWOFF2 mime type<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201807\/2018-07-25_004002.png\" width=\"366\" height=\"232\" alt=\"woff2 mime type\u8bbe\u7f6e\u622a\u56fe\" class=\"alignnone size-medium\" \/><\/p>\n<p>\u7136\u540e\uff0c\u6839\u636e\u6211\u7684\u6d4b\u8bd5\uff0c\u4f60\u8bbe\u7f6eWOFF2 mime type\u4e3aapplication\/woff2\u6587\u4ef6\u4e5f\u80fd\u6b63\u5e38\u8bc6\u522b\u3002\n<\/li>\n<\/ul>\n<h3>\u4e94\u3001\u7ed3\u8bed<\/h3>\n<p>\u62e5\u62b1WOFF2\uff0c\u65e0\u8bba\u662f\u5b57\u4f53\u56fe\u6807\uff0c\u8fd8\u662f\u5355\u7eaf\u663e\u793a\u5177\u4f53\u8bbe\u8ba1\u611f\u7684\u6587\u5b57\u3002<\/p>\n<p>\u53c2\u8003\u6587\u7ae0\uff1a<a href=\"https:\/\/gist.github.com\/sergejmueller\/cf6b4f2133bcb3e2f64a\" rel=\"nofollow\" target=\"_blank\">Basics about WOFF 2.0 <\/a><\/p>\n<p><img decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201611\/14.png\" align=\"absmiddle\"><\/p>\n<p>\u672c\u6587\u4e3a\u539f\u521b\u6587\u7ae0\uff0c\u4f1a\u7ecf\u5e38\u66f4\u65b0\u77e5\u8bc6\u70b9\u4ee5\u53ca\u4fee\u6b63\u4e00\u4e9b\u9519\u8bef\uff0c\u56e0\u6b64\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u539f\u51fa\u5904\uff0c\u65b9\u4fbf\u6eaf\u6e90\uff0c\u907f\u514d\u9648\u65e7\u9519\u8bef\u77e5\u8bc6\u7684\u8bef\u5bfc\uff0c\u540c\u65f6\u6709\u66f4\u597d\u7684\u9605\u8bfb\u4f53\u9a8c\u3002<br \/>\n\u672c\u6587\u5730\u5740\uff1a<a href=\"https:\/\/www.zhangxinxu.com\/wordpress\/?p=5474\">https:\/\/www.zhangxinxu.com\/wordpress\/?p=5474<\/a><\/p>\n<p>\uff08\u672c\u7bc7\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"\/\/image.zhangxinxu.com\/image\/blog\/201807\/woff2-thumb.jpg\" width=\"161\" height=\"100\" alt=\"\u6587\u7ae0\u5934\u56fe\" class=\"alignright size-medium\" \/><\/p>\n<p>woff\u5b57\u4f53\u57282012\u5e7412\u6708\u88abWorld Wide Web Consortium (W3C)\u63a8\u8350\u4f7f\u7528\uff0cIE9+\u6d4f\u89c8\u5668\u652f\u6301\u3002woff2\u5b57\u4f53\u6700\u65e9\u5728\u57282013\u5e747\u6708Chrome Canary\u7248\u672c\u4e0a\u53ef\u4ee5\u4f7f\u7528\uff0c\u53d1\u5c55\u5230\u73b0\u5728\uff0c\u51e0\u4e4e\u5df2\u7ecf\u6210\u4e3a\u81ea\u5b9a\u4e49\u56fe\u6807\u5b57\u4f53\u4f7f\u7528\u7684\u6807\u914d\u3002<\/p>\n<p>\u672c\u6587\u5c31\u5c06\u4ecb\u7ecd\u5173\u4e8eWOFF2\u8bf8\u591a\u57fa\u7840\u77e5\u8bc6\uff0c\u5305\u62ec\u4f18\u70b9\u7279\u6027\uff0c\u5982\u679cTTF\u5b57\u4f53\u8f6cWOFF2\u5b57\u4f53\uff0c\u5982\u4f55\u5728CSS\u4e2d\u4f7f\u7528\uff0cmime type\u8bbe\u7f6e\u7b49\uff0c\u6709\u622a\u56fe\u6709\u5fc5\u8981\u7684\u6e90\u4ee3\u7801\u5c55\u793a\u3002\u5e0c\u671b\u672c\u6587\u5185\u5bb9\u80fd\u591f\u5bf9\u60a8\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[710,416,655,1287,1285,1286],"_links":{"self":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/7848"}],"collection":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/comments?post=7848"}],"version-history":[{"count":0,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/posts\/7848\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/media?parent=7848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/categories?post=7848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhangxinxu.com\/wordpress\/wp-json\/wp\/v2\/tags?post=7848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}