{"id":14,"date":"2011-07-20T22:16:41","date_gmt":"2011-07-21T03:16:41","guid":{"rendered":"http:\/\/cbateman.com\/blogtest\/?p=14"},"modified":"2014-10-09T22:38:15","modified_gmt":"2014-10-10T03:38:15","slug":"font-face-awesomeness","status":"publish","type":"post","link":"https:\/\/cbateman.com\/blog\/font-face-awesomeness\/","title":{"rendered":"Font-Face Awesomeness"},"content":{"rendered":"<p>I still see\u00a0<a href=\"http:\/\/cufon.shoqolate.com\/generate\/\">Cufon<\/a>\u00a0used pretty frequently (which surprises me), and even worse, there must be people still\u00a0trying to use <a href=\"http:\/\/www.mikeindustries.com\/blog\/sifr\">sIFR<\/a>, because they <a href=\"http:\/\/twitter.com\/#!\/sifr\/status\/85044106488848385\">tweeted this<\/a> a couple weeks ago:<p>\r\n<blockquote><p>To whomever is still reading this, it&#8217;s 2011. Have a look at\u00a0@typekit\u00a0or\u00a0@fontdeck\u00a0or the likes, sIFR has gone unsupported for years.<\/p><\/blockquote>\r\n\r\n<p>Fortunately, we now have <a href=\"https:\/\/developer.mozilla.org\/en\/css\/@font-face\">@font-face<\/a> to put almost any font on a web page. There are two basic ways to accomplish this: 1. Serve your own font files from your own server, or 2. Use a service like <a href=\"http:\/\/typekit.com\">TypeKit <\/a>or <a href=\"http:\/\/www.google.com\/webfonts\">Google Web Fonts<\/a>.<\/p>\r\n\r\n<p>Typekit has gotten pretty popular, but I&#8217;ve been pretty skeptical about those kind of services &#8211; why not just buy the fonts you need and serve them yourself? You don&#8217;t have to pay recurring costs, you don&#8217;t have to worry about exceeding pageview limits, you don&#8217;t have to worry about the service going down, and you can use as many fonts on as many sites as you like.<\/p>\r\n\r\n<p>When I built this site, I included five embedded fonts (mostly variants of one typeface). I was feeling pretty good about it until I took a look at the &#8216;Net&#8217; tab in Firebug. My five fonts were about 90KB spread across five HTTP requests. Not fantastic &#8211; especially for mobile devices and other slow connections. And this is where Typekit and Google have come up with something that <em>might<\/em>\u00a0be worth paying for.<\/p>\r\n\r\n<p>A neat CSS trick is that you can embed files right within the style sheet wherever you have a url property, like this:<\/p>\r\n<pre class=\"pre\">background-image:url(data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIA...);<\/pre>\r\n\r\n<p>You can do this with fonts as well &#8211; which means that I can encode all five of my fonts and stick them into one style sheet &#8211; removing five HTTP requests. Awesome!<\/p>\r\n\r\n<p>But unfortunately, it&#8217;s a bit more complicated than that.<\/p>\r\n\r\n<p>If you want your fonts to work in most browsers and in older versions of iOS, you need to include four different types of font files (<a href=\"http:\/\/www.fontspring.com\/blog\/the-new-bulletproof-font-face-syntax\">like so<\/a>), and the browser will download the first compatible font file. If I include all four versions encoded into in a single style sheet &#8211; I&#8217;m going to quadruple the size of the style sheet. Less HTTP requests, but much more data. Bummer.<\/p>\r\n\r\n<p>What Typekit and Google Web Fonts do is dynamically send each browser <em>only<\/em> the compatible file type for that browser. Pretty cool. No matter how many fonts you have, they&#8217;re downloaded in a single, optimized style sheet.<\/p>\r\n\r\n<p>It would be interesting to try to set up something like this, but as far as I know, there&#8217;s no straightforward way to determine font compatibility in JavaScript (though I&#8217;m sure you could hack up something) &#8211; so you&#8217;d have to check the user agent. And that doesn&#8217;t sound like <em>tons<\/em> of fun.<\/p>\r\n\r\n<p>On the bright side, <a href=\"http:\/\/en.wikipedia.org\/wiki\/Woff\">WOFF<\/a> is gaining widespread <a href=\"http:\/\/caniuse.com\/woff\">support<\/a>: IE9+, FF 3.6+, Chrome, Safari 5.1+, Opera 11.1+, and iOS 5+.  So if you can do with supporting just those browsers &#8211; encode your WOFF files into a single style sheet and rock on.<\/p>\r\n\r\n<footer>\r\n<p>Also, note that Typekit definitely has other benefits besides performance &#8211; it&#8217;s just that most of them aren&#8217;t particularly valuable to me.<\/p>\r\n<\/footer>","protected":false},"excerpt":{"rendered":"<p>I still see\u00a0Cufon\u00a0used pretty frequently (which surprises me), and even worse, there must be people still\u00a0trying to use sIFR, because they tweeted this a couple weeks ago: To whomever is still reading this, it&#8217;s 2011. Have a look at\u00a0@typekit\u00a0or\u00a0@fontdeck\u00a0or the likes, sIFR has gone unsupported for years. Fortunately, we now have @font-face to put almost any font on a web&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-14","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/cbateman.com\/blog\/wp-json\/wp\/v2\/posts\/14"}],"collection":[{"href":"https:\/\/cbateman.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cbateman.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cbateman.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cbateman.com\/blog\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":44,"href":"https:\/\/cbateman.com\/blog\/wp-json\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":1379,"href":"https:\/\/cbateman.com\/blog\/wp-json\/wp\/v2\/posts\/14\/revisions\/1379"}],"wp:attachment":[{"href":"https:\/\/cbateman.com\/blog\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cbateman.com\/blog\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cbateman.com\/blog\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}